using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using FrameworkDAL.CustomCode.EventTypeAction; using FrameworkDAL.DTO.EventTypeAction; 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.EventTypeAction { public class EventTypeActionBLL : IEventTypeActionBLL { private readonly IEventTypeActionDAL _EventTypeActionDAL; private readonly AutoNumber _AutoNumber; private readonly IValidation _Validation; public EventTypeActionBLL(IEventTypeActionDAL IEventTypeActionDAL, AutoNumber AutoNumber, IValidation Validation) { _EventTypeActionDAL = IEventTypeActionDAL; _AutoNumber = AutoNumber; _Validation = Validation; } public async Task GetEventTypeAction(int EventTypeActionId, LoginDTO LoginDTO) { try { return await _EventTypeActionDAL.GetEventTypeAction(EventTypeActionId, LoginDTO); } catch (Exception) { throw; } } public async Task SaveEventTypeAction(EventTypeActionDTO EventTypeActionDTO, LoginDTO LoginDTO) { if (EventTypeActionDTO == null) throw new ArgumentNullException(nameof(EventTypeActionDTO)); AutoNumberDTO? autoNumberDTO = null; try { EventTypeActionDTO.EventTypeActionModifiedById = LoginDTO.UserId; EventTypeActionDTO.EventTypeActionModifiedOn = DateTime.UtcNow; int count = 1; if (EventTypeActionDTO.EventTypeActionId == 0) { autoNumberDTO = await _AutoNumber.GetAutoNumber(count, "EVENTTYPEACTION", LoginDTO); EventTypeActionDTO.EventTypeActionId = autoNumberDTO.StartNumber; EventTypeActionDTO.EventTypeActionCreatedById = LoginDTO.UserId; EventTypeActionDTO.EventTypeActionCreatedOn = DateTime.UtcNow; await _EventTypeActionDAL.SaveEventTypeAction(EventTypeActionDTO, LoginDTO); return $"{SuccessResponse.SaveSuccessMessage} {EventTypeActionDTO.EventTypeActionId}"; } else { await _EventTypeActionDAL.UpdateEventTypeAction(EventTypeActionDTO, LoginDTO); return $"{SuccessResponse.UpdateSuccessMessage} {EventTypeActionDTO.EventTypeActionId}"; } } catch (ValidationException vex) { throw new Exception(vex.Message); } catch (Exception) { if (autoNumberDTO != null && EventTypeActionDTO.EventTypeActionId > 0) await _AutoNumber.RollbackAutoNumber("EVENTTYPEACTION", EventTypeActionDTO.EventTypeActionId, LoginDTO); throw; } } public async Task DeleteEventTypeAction(int EventTypeActionId, LoginDTO LoginDTO) { try { return await _EventTypeActionDAL.DeleteEventTypeAction(EventTypeActionId, LoginDTO); } catch (Exception) { throw; } } public async Task GetSelectListEventTypeAction(CriteriaDTO criteriaDTO, LoginDTO loginDTO) { try { return await _EventTypeActionDAL.GetSelectListEventTypeAction(criteriaDTO, loginDTO); } catch (Exception) { throw; } } } }