using FrameworkDAL.CustomCode.ProgramAssembly; using FrameworkDAL.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.ResponseStandard; using GB5Shared.Validation; using System; using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; namespace FrameworkBLL.ProgramAssembly { public class ProgramAssemblyBLL : IProgramAssemblyBLL { private readonly IProgramAssemblyDAL _ProgramAssemblyDAL; private readonly AutoNumber _AutoNumber; private readonly IValidation _Validation; public ProgramAssemblyBLL(IProgramAssemblyDAL ProgramAssemblyDAL, AutoNumber AutoNumber, IValidation Validation) { _ProgramAssemblyDAL = ProgramAssemblyDAL; _AutoNumber = AutoNumber; _Validation = Validation; } public async Task GetProgramAssembly(int ProgramAssemblyId, LoginDTO LoginDTO) { try { return await _ProgramAssemblyDAL.GetProgramAssembly(ProgramAssemblyId, LoginDTO); } catch (Exception) { throw; } } public async Task SaveProgramAssembly(ProgramAssemblyDTO dto, LoginDTO LoginDTO) { if (dto == null) throw new ArgumentNullException(nameof(dto)); AutoNumberDTO? autoNumberDTO = null; try { await _Validation.NotEmpty(dto.ProgramAssemblyName, nameof(dto.ProgramAssemblyName)); dto.ProgramAssemblyModifiedById = LoginDTO.UserId; dto.ProgramAssemblyModifiedOn = DateTime.UtcNow; int count = 1; if (dto.ProgramAssemblyId == 0) { autoNumberDTO = await _AutoNumber.GetAutoNumber(count, "PROGRAMASSEMBLY", LoginDTO); dto.ProgramAssemblyId = autoNumberDTO.StartNumber; dto.ProgramAssemblyCreatedById = LoginDTO.UserId; dto.ProgramAssemblyCreatedOn = DateTime.UtcNow; await _ProgramAssemblyDAL.SaveProgramAssembly(dto, LoginDTO); return $"{SuccessResponse.SaveSuccessMessage} {dto.ProgramAssemblyId}"; } else { await _ProgramAssemblyDAL.UpdateProgramAssembly(dto, LoginDTO); return $"{SuccessResponse.UpdateSuccessMessage} {dto.ProgramAssemblyId}"; } } catch (ValidationException vex) { throw new Exception(vex.Message); } catch (Exception) { if (autoNumberDTO != null && dto.ProgramAssemblyId > 0) await _AutoNumber.RollbackAutoNumber("PROGRAMASSEMBLY", dto.ProgramAssemblyId, LoginDTO); throw; } } public async Task DeleteProgramAssembly(int ProgramAssemblyId, LoginDTO LoginDTO) { try { return await _ProgramAssemblyDAL.DeleteProgramAssembly(ProgramAssemblyId, LoginDTO); } catch (Exception) { throw; } } public async Task GetSelectListProgramAssembly(CriteriaDTO criteriaDTO, LoginDTO LoginDTO) { try { return await _ProgramAssemblyDAL.GetSelectListProgramAssembly(criteriaDTO, LoginDTO); } catch (Exception) { throw; } } } }