106 lines
3.8 KiB
C#
106 lines
3.8 KiB
C#
using _0_Framework.Application;
|
|
using CompanyManagment.App.Contracts.EmployeeBankInformation;
|
|
using CompanyManagement.Infrastructure.Excel.EmployeeBankInfo;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using ServiceHost.BaseControllers;
|
|
|
|
namespace ServiceHost.Areas.Client.Controllers;
|
|
|
|
public class EmployeeBankInfoController : ClientBaseController
|
|
{
|
|
private readonly IEmployeeBankInformationApplication _employeeBankInformationApplication;
|
|
private readonly long _workshopId;
|
|
|
|
public EmployeeBankInfoController(IEmployeeBankInformationApplication employeeBankInformationApplication,
|
|
IAuthHelper authHelper)
|
|
{
|
|
_employeeBankInformationApplication = employeeBankInformationApplication;
|
|
_workshopId = authHelper.GetWorkshopId();
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<ActionResult<List<GroupedEmployeeBankInformationViewModel>>> GetList(
|
|
EmployeeBankInformationSearchModel searchModel)
|
|
{
|
|
return await _employeeBankInformationApplication.SearchAsync(_workshopId, searchModel);
|
|
}
|
|
|
|
[HttpGet("{employeeId:long}")]
|
|
public async Task<ActionResult<GetEmployeeBankInfoDetailsDto>> GetDetails(long employeeId)
|
|
{
|
|
return await _employeeBankInformationApplication.GetDetailsByEmployeeIdAsync(_workshopId, employeeId);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult<OperationResult> Create([FromBody]CreateEmployeeInformation command)
|
|
{
|
|
command.WorkshopId = _workshopId;
|
|
return _employeeBankInformationApplication.Create(command);
|
|
}
|
|
[HttpPut]
|
|
public ActionResult<OperationResult> Edit([FromBody]EditEmployeeInformation command)
|
|
{
|
|
command.WorkshopId = _workshopId;
|
|
return _employeeBankInformationApplication.Edit(command);
|
|
}
|
|
[HttpDelete("delete-by-employee/{employeeId:long}")]
|
|
public ActionResult<OperationResult> Remove(long employeeId)
|
|
{
|
|
return _employeeBankInformationApplication.RemoveByEmployeeId(_workshopId, employeeId);
|
|
|
|
}
|
|
|
|
[HttpDelete("delete-one/{id:long}")]
|
|
public IActionResult OnPostDelete(long id)
|
|
{
|
|
var result = _employeeBankInformationApplication.Remove(id);
|
|
return new JsonResult(new
|
|
{
|
|
success = result.IsSuccedded,
|
|
message = result.Message,
|
|
});
|
|
}
|
|
|
|
[HttpPost("excel")]
|
|
public ActionResult DownloadExcel([FromBody]DownloadExcelRequest request)
|
|
{
|
|
|
|
var employeeBankInformationViewModelForExcels = _employeeBankInformationApplication.SearchForExcel(_workshopId,
|
|
new EmployeeBankInformationSearchModel() { EmployeeBankInfoIds = request.Ids });
|
|
|
|
var resultViewModel = employeeBankInformationViewModelForExcels.Select(x => new EmployeeBankInfoExcelViewModel
|
|
{
|
|
Name = x.EmployeeName,
|
|
BankAccounts = x.BankInformationList.Select(b => new BankInfoExcelViewModel()
|
|
{
|
|
IsDefault = b.IsDefault,
|
|
ShebaNumber = b.ShebaNumber,
|
|
AccountNumber = b.BankAccountNumber,
|
|
BankName = b.BankName,
|
|
CardNumber = b.CardNumber
|
|
}).ToList()
|
|
}).ToList();
|
|
|
|
var bytes = EmployeeBankInfoExcelGenerator.Generate(resultViewModel);
|
|
return File(bytes,
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
$"اطلاعات بانکی پرسنل.xlsx");
|
|
}
|
|
|
|
[HttpPost("set-default/{bankId:long}")]
|
|
public IActionResult SetDefault(long bankId)
|
|
{
|
|
var result = _employeeBankInformationApplication.SetDefault(_workshopId, bankId);
|
|
return new JsonResult(new
|
|
{
|
|
success = result.IsSuccedded,
|
|
message = result.Message,
|
|
id = result.SendId
|
|
});
|
|
}
|
|
|
|
}
|
|
public class DownloadExcelRequest
|
|
{
|
|
public List<long> Ids { get; set; }
|
|
} |