using MMDAL.CustomCode.DutyTable; using MMDAL.DTO.DutyTable; 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; using System; using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; namespace MMBLL.DutyTable { public class DutyTableBLL : IDutyTableBLL { private readonly IDutyTableDAL _DutyTableDAL; private readonly AutoNumber _AutoNumber; private readonly IValidation _Validation; public DutyTableBLL( IDutyTableDAL DutyTableDAL, AutoNumber AutoNumber, IValidation Validation) { _DutyTableDAL = DutyTableDAL; _AutoNumber = AutoNumber; _Validation = Validation; } public async Task GetDutyTable(int DutyTableId, LoginDTO LoginDTO) { try { return await _DutyTableDAL.GetDutyTable(DutyTableId, LoginDTO); } catch (Exception) { throw; } } public async Task SaveDutyTable(DutyTableDTO DutyTableDTO, LoginDTO LoginDTO) { //if (DutyTableDTO == null) throw new ArgumentNullException(nameof(DutyTableDTO)); //AutoNumberDTO? autoNumberDTO = null; try { DutyTableDTO.DutyTableModifiedById = LoginDTO.UserId; DutyTableDTO.DutyTableModifiedOn = DateTime.UtcNow; if (DutyTableDTO.DutyTableId == 0) { //autoNumberDTO = await _AutoNumber.GetAutoNumber(count, "DutyTable", LoginDTO); //DutyTableDTO.DutyTableId = autoNumberDTO.StartNumber; DutyTableDTO.DutyTableCreatedById = LoginDTO.UserId; DutyTableDTO.DutyTableCreatedOn = DateTime.UtcNow; await _DutyTableDAL.SaveDutyTable(DutyTableDTO, LoginDTO); return $"{SuccessResponse.SaveSuccess}"; } else { await _DutyTableDAL.UpdateDutyTable(DutyTableDTO, LoginDTO); return $"{SuccessResponse.UpdateSuccess}"; } } catch (ValidationException vex) { throw new Exception(vex.Message); } catch (Exception) { //if (autoNumberDTO != null && DutyTableDTO.DutyTableId > 0) // await _AutoNumber.RollbackAutoNumber("DutyTable", DutyTableDTO.DutyTableId, LoginDTO); throw; } } public async Task GetSelectListDutyTable( int FirstNumber, int MaxResult, CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { return await _DutyTableDAL.GetSelectListDutyTable( FirstNumber, MaxResult, CriteriaDTO, LoginDTO); } catch (Exception) { throw; } } public async Task DeleteDutyTable(int DutyTableId, LoginDTO LoginDTO) { try { return await _DutyTableDAL.DeleteDutyTable(DutyTableId, LoginDTO); } catch (Exception) { throw; } } public async Task GetDutyTableList(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { return await _DutyTableDAL.GetDutyTableList(CriteriaDTO, LoginDTO); } catch (Exception) { throw; } } } }