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.Login; using GB5Shared.GenerateAutoNumber; using GB5Shared.Resource.Response; using GB5Shared.Validation; using PayRollDAL.CustomeCode.EmployeeSkill; using PayRollDAL.DTO.EmployeeSkill; namespace PayRollBLL.EmployeeSkill { public class EmployeeSkillBLL : IEmployeeSkillBLL { private readonly IEmployeeSkillDAL _EmployeeSkillDAL; private readonly AutoNumber _AutoNumber; private readonly IValidation _Validation; public EmployeeSkillBLL(IEmployeeSkillDAL IEmployeeSkillDAL, AutoNumber AutoNumber, IValidation Validation) { _EmployeeSkillDAL = IEmployeeSkillDAL; _AutoNumber = AutoNumber; _Validation = Validation; } public async Task SaveEmployeeSkill(EmployeeSkillDTO EmployeeSkillDTO, LoginDTO LoginDTO) { if (EmployeeSkillDTO == null) throw new ArgumentNullException(nameof(EmployeeSkillDTO)); AutoNumberDTO? autoNumberDTO = null; try { int count = 1; if (EmployeeSkillDTO.EmployeeSkillId == 0) { autoNumberDTO = await _AutoNumber.GetAutoNumber(count, "EMPLOYEESKILL", LoginDTO); EmployeeSkillDTO.EmployeeSkillId = autoNumberDTO.StartNumber; await _EmployeeSkillDAL.SaveEmployeeSkill(EmployeeSkillDTO, LoginDTO); return $"{SuccessResponse.SaveSuccessMessage} {EmployeeSkillDTO.EmployeeSkillId}"; } else { await _EmployeeSkillDAL.UpdateEmployeeSkill(EmployeeSkillDTO, LoginDTO); return $"{SuccessResponse.UpdateSuccessMessage} {EmployeeSkillDTO.EmployeeSkillId}"; } } catch (ValidationException vex) { throw new Exception(vex.Message); } catch (Exception) { if (autoNumberDTO != null && EmployeeSkillDTO.EmployeeSkillId > 0) await _AutoNumber.RollbackAutoNumber("EMPLOYEESKILL", EmployeeSkillDTO.EmployeeSkillId, LoginDTO); throw; } } public async Task DeleteEmployeeSkill(int EmployeeId, LoginDTO LoginDTO) { try { return await _EmployeeSkillDAL.DeleteEmployeeSkill(EmployeeId, LoginDTO); } catch (Exception) { throw; } } } }