using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using DMSDAL.CustomCode.Project; using DMSDAL.DTO.Project; using GB5Shared.DTO.Framework.AutoNumber; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.GenerateAutoNumber; using GB5Shared.Resource.Response; using GB5Shared.Validation; namespace DMSBLL.Project { public class ProjectBLL : IProjectBLL { private readonly IProjectDAL _ProjectDAL; private readonly AutoNumber _AutoNumber; private readonly IValidation _Validation; public ProjectBLL(IProjectDAL ProjectDAL, AutoNumber AutoNumber, IValidation Validation) { _ProjectDAL = ProjectDAL; _AutoNumber = AutoNumber; _Validation = Validation; } public async Task GetProject(int ProjectId, LoginDTO LoginDTO) { try { return await _ProjectDAL.GetProject(ProjectId, LoginDTO); } catch (Exception) { throw; } } public async Task SaveProject(ProjectDTO ProjectDTO, LoginDTO LoginDTO) { if (ProjectDTO == null) throw new ArgumentNullException(nameof(ProjectDTO)); AutoNumberDTO? autoNumberDTO = null; try { await _Validation.NotEmpty(ProjectDTO.SpaceProjectName, nameof(ProjectDTO.SpaceProjectName)); ProjectDTO.ProjectModifiedById = LoginDTO.UserId; ProjectDTO.ProjectModifiedOn = DateTime.UtcNow; int initialId = ProjectDTO.SpaceProjectId; int count = 1 + initialId; if (initialId == 0) { AutoNumberDTO AutoNumberDTO = await _AutoNumber.GetNumberAsync(count, "SPACEPROJECT", LoginDTO); ProjectDTO.SpaceProjectId = AutoNumberDTO.StartNumber; ProjectDTO.ProjectCreatedById = LoginDTO.UserId; ProjectDTO.ProjectCreatedOn = DateTime.UtcNow; await _ProjectDAL.SaveProject(ProjectDTO, LoginDTO); return $"{SuccessResponse.SaveSuccessMessage} {ProjectDTO.SpaceProjectId}"; } else { await _ProjectDAL.UpdateProject(ProjectDTO, LoginDTO); return $"{SuccessResponse.UpdateSuccessMessage} {ProjectDTO.SpaceProjectId}"; } } catch (ValidationException vex) { throw new Exception(vex.Message); } catch (Exception) { if (autoNumberDTO != null && ProjectDTO.SpaceProjectId > 0) await _AutoNumber.RollbackAutoNumber("SPACEPROJECT", ProjectDTO.SpaceProjectId, LoginDTO); throw; } } public async Task DeleteProject(int ProjectId, LoginDTO LoginDTO) { try { return await _ProjectDAL.DeleteProject(ProjectId, LoginDTO); } catch (Exception) { throw; } } //public async Task GetSelectListProject(CriteriaDTO criteriaDTO, LoginDTO LoginDTO) //{ // try // { // return await _ProjectDAL.GetSelectListProject(criteriaDTO, LoginDTO); // } // catch (Exception) // { // throw; // } //} } }