162 lines
5.9 KiB
C#
162 lines
5.9 KiB
C#
using _0_Framework.Application;
|
|
using CompanyManagment.App.Contracts.Employee;
|
|
using CompanyManagment.App.Contracts.EmployeeDocuments;
|
|
using CompanyManagment.App.Contracts.Error;
|
|
using CompanyManagment.App.Contracts.Workshop;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using System.Security.Claims;
|
|
|
|
namespace ServiceHost.Areas.Client.Pages.Company.EmployeesDocuments
|
|
{
|
|
[Authorize]
|
|
public class IndexModel : PageModel
|
|
{
|
|
private readonly IPasswordHasher _passwordHasher;
|
|
private readonly IAuthHelper _authHelper;
|
|
private readonly IWorkshopApplication _workshopApplication;
|
|
private readonly IWebHostEnvironment _webHostEnvironment;
|
|
private readonly IEmployeeDocumentsApplication _employeeDocumentsApplication;
|
|
private readonly IHttpContextAccessor _contextAccessor;
|
|
private readonly long _workshopId;
|
|
|
|
public string WorkshopFullName;
|
|
|
|
public IndexModel(IPasswordHasher passwordHasher, IWorkshopApplication workshopApplication, IEmployeeDocumentsApplication employeeDocumentsApplication, IAuthHelper authHelper, IWebHostEnvironment webHostEnvironment, IHttpContextAccessor contextAccessor)
|
|
{
|
|
_passwordHasher = passwordHasher;
|
|
_workshopApplication = workshopApplication;
|
|
_employeeDocumentsApplication = employeeDocumentsApplication;
|
|
_authHelper = authHelper;
|
|
_webHostEnvironment = webHostEnvironment;
|
|
_contextAccessor = contextAccessor;
|
|
|
|
var workshopHash = _contextAccessor.HttpContext?.User.FindFirstValue("WorkshopSlug");
|
|
_workshopId = _passwordHasher.SlugDecrypt(workshopHash);
|
|
|
|
if (_workshopId < 1)
|
|
throw new InvalidDataException("اختلال در کارگاه");
|
|
}
|
|
|
|
public IActionResult OnGet()
|
|
{
|
|
WorkshopFullName= _workshopApplication.GetWorkshopFullname(_workshopId);
|
|
|
|
return Page();
|
|
}
|
|
|
|
public IActionResult OnGetEmployeeDocumentsAjax(string employeeName, int pageIndex, string searchMode = "")
|
|
{
|
|
EmployeeDocumentSearchMode mode;
|
|
switch (searchMode.ToLower())
|
|
{
|
|
case "all":
|
|
mode = EmployeeDocumentSearchMode.All;
|
|
break;
|
|
case "active":
|
|
mode = EmployeeDocumentSearchMode.ActiveEmployees;
|
|
break;
|
|
case "deactive":
|
|
mode = EmployeeDocumentSearchMode.DeactiveEmployees;
|
|
break;
|
|
default:
|
|
mode = EmployeeDocumentSearchMode.All;
|
|
break;
|
|
}
|
|
|
|
List<EmployeeDocumentsViewModel> result = _employeeDocumentsApplication.SearchForClient(new SearchEmployeeDocuments()
|
|
{
|
|
WorkshopId = _workshopId,
|
|
PageIndex = pageIndex,
|
|
EmployeeName = employeeName
|
|
}, mode);
|
|
|
|
return new JsonResult(new
|
|
{
|
|
IsSuccedded = true,
|
|
data = result,
|
|
pageIndex = result.Count()
|
|
});
|
|
|
|
}
|
|
|
|
public IActionResult OnGetCreateUploadDocument(long employeeId)
|
|
{
|
|
var employeeDocument = _employeeDocumentsApplication.GetDetailsForClient(employeeId, _workshopId);
|
|
|
|
return Partial("ModalUploadDocument", employeeDocument);
|
|
}
|
|
|
|
public IActionResult OnPostCreateUploadDocument(AddEmployeeDocumentItem command)
|
|
{
|
|
command.WorkshopId = _workshopId;
|
|
|
|
var result = _employeeDocumentsApplication.AddEmployeeDocumentItemForClient(command);
|
|
var employeeDocument = _employeeDocumentsApplication.GetDetailsForClient(command.EmployeeId, _workshopId);
|
|
return new JsonResult(new
|
|
{
|
|
isSuccedded = result.IsSuccedded,
|
|
message = result.Message,
|
|
imageSrc = employeeDocument
|
|
});
|
|
}
|
|
|
|
public IActionResult OnPostRemoveEmployeeDocumentByLabel(long employeeId, DocumentItemLabel label)
|
|
{
|
|
var result = _employeeDocumentsApplication.DeleteEmployeeMultipleUnsubmittedDocumentsByLabel(_workshopId, employeeId,
|
|
label);
|
|
return new JsonResult(new
|
|
{
|
|
isSuccedded = result.IsSuccedded,
|
|
message = result.Message
|
|
});
|
|
}
|
|
|
|
public IActionResult OnPostSaveSubmit(SubmitEmployeeDocuments cmd)
|
|
{
|
|
var result = _employeeDocumentsApplication.SubmitDocumentItemsByClient(cmd);
|
|
|
|
return new JsonResult(new
|
|
{
|
|
isSuccedded = result.IsSuccedded,
|
|
message = result.Message,
|
|
});
|
|
}
|
|
|
|
public IActionResult OnPostCancelOperation(long workshopId, long employeeId)
|
|
{
|
|
var result = _employeeDocumentsApplication.DeleteUnsubmittedItems(_workshopId, employeeId);
|
|
return new JsonResult(new
|
|
{
|
|
success = result.IsSuccedded,
|
|
message = result.Message,
|
|
});
|
|
}
|
|
|
|
public IActionResult OnGetShowPicture(string filePath)
|
|
{
|
|
if (string.IsNullOrEmpty(filePath))
|
|
return NotFound();
|
|
|
|
|
|
if (!System.IO.File.Exists(filePath))
|
|
return NotFound();
|
|
|
|
var contentType = Tools.GetContentTypeImage(Path.GetExtension(filePath));
|
|
return PhysicalFile(filePath, contentType);
|
|
}
|
|
|
|
public IActionResult OnPostGroupSave(long employeeId, List<AddEmployeeDocumentItem> command)
|
|
{
|
|
var result = _employeeDocumentsApplication.AddRangeEmployeeDocumentItemsByClient(_workshopId, employeeId, command);
|
|
|
|
return new JsonResult(new
|
|
{
|
|
isSuccedded = result.IsSuccedded,
|
|
message = result.Message,
|
|
});
|
|
}
|
|
}
|
|
}
|