using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using FrameworkDAL.CustomCode.RoleVsPortlet; using FrameworkDAL.DTO.Portlet; 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; namespace FrameworkBLL.RoleVsPortlet { public class RoleVsPortletBLL : IRoleVsPortletBLL { private readonly IRoleVsPortletDAL _RoleVsPortletDAL; private readonly AutoNumber _AutoNumber; private readonly IValidation _Validation; public RoleVsPortletBLL(IRoleVsPortletDAL RoleVsPortletDAL, AutoNumber AutoNumber, IValidation Validation) { _RoleVsPortletDAL = RoleVsPortletDAL; _AutoNumber = AutoNumber; _Validation = Validation; } public async Task GetRoleVsPortlet(int RoleId, LoginDTO LoginDTO) { try { return await _RoleVsPortletDAL.GetRoleVsPortlet(RoleId, LoginDTO); } catch (Exception) { throw; } } public async Task SaveRoleVsPortlet(RoleVsPortletDTO RoleVsPortletDTO, LoginDTO LoginDTO) { if (RoleVsPortletDTO == null) throw new ArgumentNullException(nameof(RoleVsPortletDTO)); AutoNumberDTO? autoNumberDTO = null; try { int count = 1; if (RoleVsPortletDTO.RoleVsPortletId == 0) { autoNumberDTO = await _AutoNumber.GetAutoNumber(count, "ROLEVSPORTLET", LoginDTO); RoleVsPortletDTO.RoleVsPortletId = autoNumberDTO.StartNumber; await _RoleVsPortletDAL.SaveRoleVsPortlet(RoleVsPortletDTO, LoginDTO); return $"{SuccessResponse.SaveSuccessMessage} {RoleVsPortletDTO.RoleVsPortletId}"; } else { await _RoleVsPortletDAL.UpdateRoleVsPortlet(RoleVsPortletDTO, LoginDTO); return $"{SuccessResponse.UpdateSuccessMessage} {RoleVsPortletDTO.RoleVsPortletId}"; } } catch (ValidationException vex) { throw new Exception(vex.Message); } catch (Exception) { if (autoNumberDTO != null && RoleVsPortletDTO.RoleVsPortletId > 0) await _AutoNumber.RollbackAutoNumber("ROLEVSPORTLET", RoleVsPortletDTO.RoleVsPortletId, LoginDTO); throw; } } public async Task DeleteRoleVsPortlet(int RoleId, LoginDTO LoginDTO) { try { return await _RoleVsPortletDAL.DeleteRoleVsPortlet(RoleId, LoginDTO); } catch (Exception) { throw; } } public async Task GetRoleVsPortletWithRoleAndPage(int RoleId, int PageId, string SearchValue, LoginDTO LoginDTO) { try { return await _RoleVsPortletDAL.GetRoleVsPortletWithRoleAndPage(RoleId, PageId, SearchValue, LoginDTO); } catch (Exception) { throw; } } public async Task DeleteRoleVsPortletWithRoleAndPage(int RoleId, int PageId, LoginDTO LoginDTO) { try { return await _RoleVsPortletDAL.DeleteRoleVsPortletWithRoleAndPage(RoleId, PageId, LoginDTO); } catch (Exception) { throw; } } public async Task GetPageForRoleMenu(CriteriaDTO criteriaDTO, LoginDTO loginDTO) { try { return await _RoleVsPortletDAL.GetPageForRoleMenu(criteriaDTO, loginDTO); } catch (Exception) { throw; } } public async Task GetRoleVsPortletForUpdateUserVsPortlet(int RoleId, LoginDTO LoginDTO) { try { return await _RoleVsPortletDAL.GetRoleVsPortletForUpdateUserVsPortlet(RoleId, LoginDTO); } catch (Exception) { throw; } } public async Task GetUserVsPortletForDeleteUserVsPortlet(int RoleId, LoginDTO LoginDTO) { try { return await _RoleVsPortletDAL.GetUserVsPortletForDeleteUserVsPortlet(RoleId, LoginDTO); } catch (Exception) { throw; } } } }