diff --git a/CompanyManagment.App.Contracts/EmployeeDocuments/IEmployeeDocumentsApplication.cs b/CompanyManagment.App.Contracts/EmployeeDocuments/IEmployeeDocumentsApplication.cs index a6ad4af9..29d99e89 100644 --- a/CompanyManagment.App.Contracts/EmployeeDocuments/IEmployeeDocumentsApplication.cs +++ b/CompanyManagment.App.Contracts/EmployeeDocuments/IEmployeeDocumentsApplication.cs @@ -53,6 +53,12 @@ namespace CompanyManagment.App.Contracts.EmployeeDocuments Task GetAdminWorkFlowCountForNewEmployees(List workshopIds); OperationResult RemoveByAdmin(long documentItemId); Task GetCheckerWorkFlowCount(); + + /// + /// برای افزودن یکباره مدارک در افزودن پرسنل توسط ادمین + /// + OperationResult AddRangeEmployeeDocumentItemsByAdmin(long workshopId, long employeeId, + List command); } } diff --git a/CompanyManagment.Application/EmployeeDocumentsApplication.cs b/CompanyManagment.Application/EmployeeDocumentsApplication.cs index 5e7e133e..ba698e5b 100644 --- a/CompanyManagment.Application/EmployeeDocumentsApplication.cs +++ b/CompanyManagment.Application/EmployeeDocumentsApplication.cs @@ -1386,6 +1386,81 @@ namespace CompanyManagment.Application { return await _employeeDocumentsRepository.GetCheckerWorkFlowCount(); } + + public OperationResult AddRangeEmployeeDocumentItemsByAdmin(long workshopId, long employeeId, List command) + { + OperationResult op = new(); + + var (uploaderId, uploaderType) = _authHelper.GetUserTypeWithId(); + + if (!_employeeRepository.Exists(x => x.id == employeeId)) + + return op.Failed("پرسنل یافت نشد"); + + + if (!_workshopRepository.Exists(x => x.id == workshopId)) + return op.Failed("کارگاه وجود ندارد"); + + + var entity = + _employeeDocumentsRepository.GetByEmployeeIdWorkshopIdWithItems(employeeId, workshopId); + + + + using var scope = new TransactionScope(); + + + //if record doesn't exist but employee exists and also the workshop, create a new record + if (entity == null) + { + var opCreate = Create(new CreateEmployeeDocuments() + { EmployeeId = employeeId, WorkshopId = workshopId }); + if (opCreate.IsSuccedded == false) return opCreate; + entity = _employeeDocumentsRepository.GetByEmployeeIdWorkshopId(employeeId, workshopId); + } + + List newEntities = new(); + foreach (var item in command) + { + DeleteMultipleUnsubmittedDocumentsByLabel(entity, item.Label, uploaderType); + + var mediaOpResult = UploadDocumentItemFile(item.PictureFile, item.Label.ToString(), + $"temp/{workshopId}/{employeeId}"); + + if (mediaOpResult.IsSuccedded == false) + return mediaOpResult; + + + //if the mediaId is already in use in our table return failed + if (_employeeDocumentItemRepository.Exists(x => x.MediaId == mediaOpResult.SendId)) + return op.Failed("امکان ثبت رکورد تکراری وجود ندارد"); + + var newEntity = new EmployeeDocumentItem(workshopId, employeeId, mediaOpResult.SendId, entity.id, item.Label, uploaderId, uploaderType, DocumentStatus.SubmittedByAdmin); + newEntities.Add(newEntity); + } + + var currentItems = entity.EmployeeDocumentItemCollection.GroupBy(x => x.DocumentLabel) + .Where(x => command.Any(a => a.Label == x.Key)) + .Select(x => x.MaxBy(y => y.CreationDate)); + + //This can bite! + _employeeDocumentItemRepository.RemoveRange(currentItems); + _employeeDocumentItemRepository.SaveChanges(); + + _employeeDocumentItemRepository.AddRange(newEntities); + _employeeDocumentItemRepository.SaveChanges(); + + SubmitDocumentItemsByEmployeeIdWorkshopId(employeeId, workshopId); + + entity.UpdateIsConfirmed(); + entity.UpdateIsSentToChecker(); + _employeeDocumentsRepository.SaveChanges(); + + scope.Complete(); + return op.Succcedded(entity.id); + } + + #endregion diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/WorkFlow/EmployeesDocuments.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/Company/WorkFlow/EmployeesDocuments.cshtml.cs index 2cfd02e2..b23f3a81 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/WorkFlow/EmployeesDocuments.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/Company/WorkFlow/EmployeesDocuments.cshtml.cs @@ -21,7 +21,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.WorkFlow private readonly IAuthHelper _authHelper; public int EmployeeDocumentsAwaitingSubmitCount; - public EmployeesDocumentsModel(IAdminWorkFlowApplication adminWorkFlowApplication, IWorkshopApplication workshopApplication, IEmployeeDocumentsApplication employeeDocumentsApplication, IWorkshopAccountRepository workshopAccountRepository, IAuthHelper authHelper) + public EmployeesDocumentsModel(IAdminWorkFlowApplication adminWorkFlowApplication, IWorkshopApplication workshopApplication, IEmployeeDocumentsApplication employeeDocumentsApplication, IWorkshopAccountRepository workshopAccountRepository, IAuthHelper authHelper) { _adminWorkFlowApplication = adminWorkFlowApplication; _workshopApplication = workshopApplication; @@ -148,5 +148,15 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.WorkFlow message = result.Message }); } + + public IActionResult OnPostGroupSave(long workshopId, long employeeId, List command) + { + var result = _employeeDocumentsApplication.AddRangeEmployeeDocumentItemsByAdmin(workshopId, employeeId, command); + return new JsonResult(new + { + success = result.IsSuccedded, + message = result.Message + }); + } } } diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/WorkFlow/_ModalEmployeeDocuments/ModalEmployeeEdit.cshtml b/ServiceHost/Areas/AdminNew/Pages/Company/WorkFlow/_ModalEmployeeDocuments/ModalEmployeeEdit.cshtml index c7ecb89e..b257396c 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/WorkFlow/_ModalEmployeeDocuments/ModalEmployeeEdit.cshtml +++ b/ServiceHost/Areas/AdminNew/Pages/Company/WorkFlow/_ModalEmployeeDocuments/ModalEmployeeEdit.cshtml @@ -26,7 +26,7 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+