using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using FrameworkDAL.CustomCode.EventType; using FrameworkDAL.DTO.EventType; using GB5Shared.DTO.Framework.AutoNumber; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.GenerateAutoNumber; using GB5Shared.Resource.Response; using GB5Shared.ResponseStandard; using GB5Shared.Validation; namespace FrameworkBLL.EventType { public class EventTypeBLL : IEventTypeBLL { private readonly IEventTypeDAL _EventTypeDAL; private readonly AutoNumber _autoNumber; private readonly IValidation _Validation; public EventTypeBLL(IEventTypeDAL EventTypeDAL, AutoNumber autoNumber,IValidation Validation) { _EventTypeDAL = EventTypeDAL; _autoNumber = autoNumber; _Validation = Validation; } public async Task GetEventType(int EventTypeId, LoginDTO LoginDTO) { try { return await _EventTypeDAL.GetEventType(EventTypeId, LoginDTO); } catch (Exception) { throw; } } public async Task SaveEventType(EventTypeDTO EventTypeDTO, LoginDTO LoginDTO) { if (EventTypeDTO == null) throw new ArgumentNullException(nameof(EventTypeDTO)); try { await _Validation.NotEmpty(EventTypeDTO.EventTypeCode, nameof(EventTypeDTO.EventTypeCode)); await _Validation.NotEmpty(EventTypeDTO.EventTypeName, nameof(EventTypeDTO.EventTypeName)); EventTypeDTO.EventTypeModifiedById = LoginDTO.UserId; EventTypeDTO.EventTypeModifiedOn = DateTime.UtcNow; int initialId = EventTypeDTO.EventTypeId; int count = 1 + initialId; if (initialId == 0) { AutoNumberDTO AutoNumberDTO = await _autoNumber.GetNumberAsync(count, "EVENTTYPE", LoginDTO); EventTypeDTO.EventTypeId = AutoNumberDTO.StartNumber; EventTypeDTO.EventTypeCreatedById = LoginDTO.UserId; EventTypeDTO.EventTypeCreatedOn = DateTime.UtcNow; await _EventTypeDAL.SaveEventType(EventTypeDTO, LoginDTO); return $"{SuccessResponse.SaveSuccessMessage} {EventTypeDTO.EventTypeId}"; } else { await _EventTypeDAL.UpdateEventType(EventTypeDTO, LoginDTO); return $"{SuccessResponse.UpdateSuccessMessage} {EventTypeDTO.EventTypeId}"; } } catch (Exception) { throw; } } public async Task GetSelectListEventType(CriteriaDTO criteriaDTO, LoginDTO loginDTO) { try { return await _EventTypeDAL.GetSelectListEventType(criteriaDTO, loginDTO); } catch (Exception) { throw; } } public async Task GetSelectListDetailEventType(int FirstNumber, int MaxResult, CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { return await _EventTypeDAL.GetSelectListDetailEventType(FirstNumber, MaxResult, CriteriaDTO, LoginDTO); } catch (Exception ex) { throw new Exception("Error in GetSelectListDetailEventType", ex); } } public async Task DeleteEventType(int EventTypeId, LoginDTO LoginDTO) { try { return await _EventTypeDAL.DeleteEventType(EventTypeId, LoginDTO); } catch (Exception) { throw; } } } }