using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using FrameworkDAL.CustomCode.PortletVsMenu; using FrameworkDAL.DTO.Portlet; using GB5Shared.DTO.Framework.AutoNumber; using GB5Shared.DTO.Framework.Login; using GB5Shared.GenerateAutoNumber; using GB5Shared.Resource.Response; using GB5Shared.Validation; namespace FrameworkBLL.PortletVsMenu { public class PortletVsMenuBLL : IPortletVsMenuBLL { private readonly IPortletVsMenuDAL _PortletVsMenuDAL; private readonly AutoNumber _AutoNumber; private readonly IValidation _Validation; public PortletVsMenuBLL(IPortletVsMenuDAL IPortletVsMenuDAL, AutoNumber AutoNumber, IValidation Validation) { _PortletVsMenuDAL = IPortletVsMenuDAL; _AutoNumber = AutoNumber; _Validation = Validation; } public async Task GetPortletVsMenu(int PortletId, LoginDTO LoginDTO) { try { return await _PortletVsMenuDAL.GetPortletVsMenu(PortletId, LoginDTO); } catch (Exception) { throw; } } public async Task SavePortletVsMenu(PortletVsMenuDTO PortletVsMenuDTO, LoginDTO LoginDTO) { if (PortletVsMenuDTO == null) throw new ArgumentNullException(nameof(PortletVsMenuDTO)); AutoNumberDTO? autoNumberDTO = null; try { int count = 1; if (PortletVsMenuDTO.PortletVsMenuId == 0) { autoNumberDTO = await _AutoNumber.GetAutoNumber(count, "PORTLETVSMENU", LoginDTO); PortletVsMenuDTO.PortletVsMenuId = autoNumberDTO.StartNumber; await _PortletVsMenuDAL.SavePortletVsMenu(PortletVsMenuDTO, LoginDTO); return $"{SuccessResponse.SaveSuccessMessage} {PortletVsMenuDTO.PortletVsMenuId}"; } else { await _PortletVsMenuDAL.UpdatePortletVsMenu(PortletVsMenuDTO, LoginDTO); return $"{SuccessResponse.UpdateSuccessMessage} {PortletVsMenuDTO.PortletVsMenuId}"; } } catch (ValidationException vex) { throw new Exception(vex.Message); } catch (Exception) { if (autoNumberDTO != null && PortletVsMenuDTO.PortletVsMenuId > 0) await _AutoNumber.RollbackAutoNumber("PORTLETVSMENU", PortletVsMenuDTO.PortletVsMenuId, LoginDTO); throw; } } public async Task DeletePortletVsMenu(int PortletId, LoginDTO LoginDTO) { try { return await _PortletVsMenuDAL.DeletePortletVsMenu(PortletId, LoginDTO); } catch (Exception) { throw; } } } }