using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.Resource.Response; using Newtonsoft.Json; using PayRollDAL.CustomeCode.OULevelSetting; using PayRollDAL.DTO.OULevelSetting; namespace PayRollBLL.OULevelSetting { public class OULevelSettingBLL : IOULevelSettingBLL { private readonly IOULevelSettingDAL _OULevelSettingDAL; public OULevelSettingBLL(IOULevelSettingDAL OULevelSettingDAL) { _OULevelSettingDAL = OULevelSettingDAL; } public async Task GetOULevelSetting(int OUId, LoginDTO LoginDTO) { try { var result = await _OULevelSettingDAL.GetOULevelSetting(OUId, LoginDTO); return JsonConvert.SerializeObject(result); } catch (Exception) { throw; } } public async Task SaveOULevelSetting(OULevelSettingDTO OULevelSettingDTO, LoginDTO LoginDTO) { if (OULevelSettingDTO == null) throw new ArgumentNullException(nameof(OULevelSettingDTO)); try { bool exists = await _OULevelSettingDAL.CheckOULevelSettingExists(OULevelSettingDTO.Id, LoginDTO); if (exists) { await _OULevelSettingDAL.UpdateOULevelSetting(OULevelSettingDTO, LoginDTO); return $"{SuccessResponse.UpdateSuccessMessage} {OULevelSettingDTO.Id}"; } else { await _OULevelSettingDAL.SaveOULevelSetting(OULevelSettingDTO, LoginDTO); return $"{SuccessResponse.SaveSuccessMessage} {OULevelSettingDTO.Id}"; } } catch (Exception) { throw; } } public async Task DeleteOULevelSetting(int OUId, LoginDTO LoginDTO) { try { return await _OULevelSettingDAL.DeleteOULevelSetting(OUId, LoginDTO); } catch (Exception) { throw; } } public async Task GetOULevelSettingFields(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { var result = await _OULevelSettingDAL.GetOULevelSettingFields(CriteriaDTO, LoginDTO); return JsonConvert.SerializeObject(result); } catch (Exception) { throw; } } public async Task SaveOULevelSettingForAllOu(OULevelSettingDTO OULevelSettingDTO, LoginDTO LoginDTO) { if (OULevelSettingDTO == null) throw new ArgumentNullException(nameof(OULevelSettingDTO)); try { var ouIds = await _OULevelSettingDAL.GetAllActiveOuIds(LoginDTO); foreach (var ouId in ouIds) { OULevelSettingDTO.Id = ouId; LoginDTO.WorkOUId = ouId; await SaveOULevelSetting(OULevelSettingDTO, LoginDTO); } return "All Ou details posted.."; } catch (Exception) { throw; } } } }