using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using AdminBLL.Allocation; using AdminDAL.CustomCode.Allocation; using AdminDAL.DTO.Allocation; 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; namespace AdminBLL.MAllocation { public class AllocationBLL : IAllocationBLL { private readonly IAllocationDAL _AllocationDAL; private readonly AutoNumber _AutoNumber; private readonly IValidation _Validation; public AllocationBLL(IAllocationDAL IAllocationDAL, AutoNumber AutoNumber,IValidation validation) { _AllocationDAL = IAllocationDAL; _AutoNumber = AutoNumber; _Validation = validation; } public async Task GetAllocation(int MAllocationId, LoginDTO LoginDTO) { try { return await _AllocationDAL.GetAllocation(MAllocationId, LoginDTO); } catch (Exception) { throw; } } public async Task> GetSelectListMAllocationSplit(int FirstNumber, int MaxResult, CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { return await _AllocationDAL.GetSelectListMAllocationSplit(FirstNumber, MaxResult, CriteriaDTO, LoginDTO); } catch (Exception) { throw; } } public async Task GetSelectListAllocation(int FirstNumber, int MaxResult, CriteriaDTO criteriaDTO, LoginDTO loginDTO) { try { return await _AllocationDAL.GetSelectListAllocation(FirstNumber, MaxResult, criteriaDTO, loginDTO); } catch (Exception) { throw; } } public async Task SaveAllocation(MAllocationDTO MAllocationDTO, LoginDTO LoginDTO) { if (MAllocationDTO == null) throw new ArgumentNullException(nameof(MAllocationDTO)); try { await _Validation.NotEmpty(MAllocationDTO.MAllocationName, nameof(MAllocationDTO.MAllocationName)); MAllocationDTO.MAllocationModifiedById = LoginDTO.UserId; MAllocationDTO.MAllocationModifiedOn = DateTime.UtcNow; int initialId = MAllocationDTO.MAllocationId; int count = 1 + initialId; if (initialId == 0) { AutoNumberDTO AutoNumberDTO = await _AutoNumber.GetNumberAsync(count, "ALLOCATION", LoginDTO); MAllocationDTO.MAllocationId = AutoNumberDTO.StartNumber; MAllocationDTO.MAllocationCreatedById = LoginDTO.UserId; MAllocationDTO.MAllocationCreatedOn = DateTime.UtcNow; await _AllocationDAL.SaveAllocation(MAllocationDTO, LoginDTO); return $"{SuccessResponse.SaveSuccessMessage} {MAllocationDTO.MAllocationId}"; } else { await _AllocationDAL.UpdateAllocation(MAllocationDTO, LoginDTO); return $"{SuccessResponse.UpdateSuccessMessage} {MAllocationDTO.MAllocationId}"; } } catch (Exception) { throw; } } public async Task DeleteAllocation(int MAllocationId, LoginDTO LoginDTO) { try { return await _AllocationDAL.DeleteAllocation(MAllocationId, LoginDTO); } catch (Exception) { throw; } } } }