using System.ComponentModel.DataAnnotations; using GB5Shared.DTO.Framework.AutoNumber; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.GenerateAutoNumber; using GB5Shared.Validation; using MMDAL.CustomCode.NDTMethod; using MMDAL.DTO.NDTMethod; namespace MMBLL.NDTMethod { public class NDTMethodBLL : INDTMethodBLL { private readonly INDTMethodDAL _NDTMethodDAL; private readonly AutoNumber _AutoNumber; private readonly IValidation _Validation; public NDTMethodBLL(INDTMethodDAL NDTMethodDAL, AutoNumber AutoNumber, IValidation Validation) { _NDTMethodDAL = NDTMethodDAL; _AutoNumber = AutoNumber; _Validation = Validation; } public async Task GetNDTMethod(int NDTMethodId, LoginDTO LoginDTO) { try { return await _NDTMethodDAL.GetNDTMethod(NDTMethodId, LoginDTO); } catch (Exception) { throw; } } public async Task GetSelectListNDTMethod(int FirstNumber, int MaxResult, CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { return await _NDTMethodDAL.GetSelectListNDTMethod(FirstNumber, MaxResult, CriteriaDTO, LoginDTO); } catch (Exception) { throw; } } public async Task SaveNDTMethod(NDTMethodDTO NDTMethodDTO, LoginDTO LoginDTO) { if (NDTMethodDTO == null) throw new ArgumentNullException(nameof(NDTMethodDTO)); AutoNumberDTO? autoNumberDTO = null; try { await _Validation.NotEmpty(NDTMethodDTO.NDTMethodCode, nameof(NDTMethodDTO.NDTMethodCode)); await _Validation.NotEmpty(NDTMethodDTO.NDTMethodName, nameof(NDTMethodDTO.NDTMethodName)); NDTMethodDTO.NDTMethodModifiedById = LoginDTO.UserId; NDTMethodDTO.NDTMethodModifiedOn = DateTime.UtcNow; int initialId = NDTMethodDTO.NDTMethodId; if (initialId == 0) { //autoNumberDTO = await _AutoNumber.GetNumberAsync(1, "NDTMETHOD", LoginDTO); //NDTMethodDTO.NDTMethodId = autoNumberDTO.StartNumber; NDTMethodDTO.NDTMethodCreatedById = LoginDTO.UserId; NDTMethodDTO.NDTMethodCreatedOn = DateTime.UtcNow; await _NDTMethodDAL.SaveNDTMethod(NDTMethodDTO, LoginDTO); return "Details Saved Successfully."; } else { await _NDTMethodDAL.UpdateNDTMethod(NDTMethodDTO, LoginDTO); return "Details Updated Successfully."; } } catch (ValidationException vex) { throw new Exception(vex.Message); } catch (Exception) { if (autoNumberDTO != null && NDTMethodDTO.NDTMethodId > 0) await _AutoNumber.RollbackAutoNumber("NDTMETHOD", NDTMethodDTO.NDTMethodId, LoginDTO); throw; } } public async Task DeleteNDTMethod(int NDTMethodId, LoginDTO LoginDTO) { try { return await _NDTMethodDAL.DeleteNDTMethod(NDTMethodId, LoginDTO); } catch (Exception) { throw; } } } }