using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; 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 PayRollDAL.CustomeCode.EmployeeNominee; using PayRollDAL.DTO.EmployeeNominee; namespace PayRollBLL.EmployeeNominee { public class EmployeeNomineeBLL : IEmployeeNomineeBLL { private readonly IEmployeeNomineeDAL _EmployeeNomineeDAL; private readonly AutoNumber _AutoNumber; private readonly IValidation _Validation; public EmployeeNomineeBLL(IEmployeeNomineeDAL IEmployeeNomineeDAL, AutoNumber AutoNumber, IValidation Validation) { _EmployeeNomineeDAL = IEmployeeNomineeDAL; _AutoNumber = AutoNumber; _Validation = Validation; } public async Task SaveEmployeeNominee(EmployeeNomineeDTO EmployeeNomineeDTO, LoginDTO LoginDTO) { if (EmployeeNomineeDTO == null) throw new ArgumentNullException(nameof(EmployeeNomineeDTO)); AutoNumberDTO? autoNumberDTO = null; try { int count = 1; if (EmployeeNomineeDTO.EmployeeNomineeId == 0) { autoNumberDTO = await _AutoNumber.GetAutoNumber(count, "EMPLOYEENOMINEE", LoginDTO); EmployeeNomineeDTO.EmployeeNomineeId = autoNumberDTO.StartNumber; await _EmployeeNomineeDAL.SaveEmployeeNominee(EmployeeNomineeDTO, LoginDTO); return $"{SuccessResponse.SaveSuccessMessage} {EmployeeNomineeDTO.EmployeeNomineeId}"; } else { await _EmployeeNomineeDAL.UpdateEmployeeNominee(EmployeeNomineeDTO, LoginDTO); return $"{SuccessResponse.UpdateSuccessMessage} {EmployeeNomineeDTO.EmployeeNomineeId}"; } } catch (ValidationException vex) { throw new Exception(vex.Message); } catch (Exception) { if (autoNumberDTO != null && EmployeeNomineeDTO.EmployeeNomineeId > 0) await _AutoNumber.RollbackAutoNumber("EMPLOYEENOMINEE", EmployeeNomineeDTO.EmployeeNomineeId, LoginDTO); throw; } } public async Task DeleteEmployeeNomineeOnEmployee(int EmployeeId, int NomineeType, LoginDTO LoginDTO) { try { return await _EmployeeNomineeDAL.DeleteEmployeeNomineeOnEmployee(EmployeeId, NomineeType, LoginDTO); } catch (Exception) { throw; } } public async Task DeleteEmployeeNominee(int EmployeeNomineeId, LoginDTO LoginDTO) { try { return await _EmployeeNomineeDAL.DeleteEmployeeNominee(EmployeeNomineeId, LoginDTO); } catch (Exception) { throw; } } public async Task GetSelectListEmployeeNominee(int FirstNumber, int MaxResult, CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { return await _EmployeeNomineeDAL.GetSelectListEmployeeNominee(FirstNumber, MaxResult, CriteriaDTO, LoginDTO); } catch (Exception ex) { throw new Exception("Error in GetSelectListEmployeeNominee", ex); } } } }