using System.ComponentModel.DataAnnotations; using FrameworkDAL.CustomCode.FieldComponent; using GB5Shared.DTO.Framework.AutoNumber; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.GenerateAutoNumber; using GB5Shared.Validation; using GB5Shared.ResponseStandard; using CMSDAL.CustomCode.FieldComponent; using CMSDAL.DTO.FieldComponent; namespace CMSBLL.FieldComponent { public class FieldComponentBLL : IFieldComponentBLL { private readonly IFieldComponentDAL _FieldComponentDAL; private readonly AutoNumber _AutoNumber; private readonly IValidation _Validation; public FieldComponentBLL(IFieldComponentDAL FieldComponentDAL, AutoNumber AutoNumber, IValidation validation) { _FieldComponentDAL = FieldComponentDAL; _AutoNumber = AutoNumber; _Validation = validation; } public async Task GetFieldComponent(Guid FieldComponentId, LoginDTO LoginDTO) { try { return await _FieldComponentDAL.GetFieldComponent(FieldComponentId, LoginDTO); } catch (Exception) { throw; } } public async Task SaveFieldComponent(FieldComponentDTO FieldComponentDTO, LoginDTO LoginDTO) { if (FieldComponentDTO == null) throw new ArgumentNullException(nameof(FieldComponentDTO)); try { await _Validation.NotEmpty(FieldComponentDTO.FieldComponentName, nameof(FieldComponentDTO.FieldComponentName)); FieldComponentDTO.ModifiedById = LoginDTO.UserId; FieldComponentDTO.ModifiedOn = DateTime.UtcNow; // NEW FieldComponent if (FieldComponentDTO.FieldComponentId == Guid.Empty) { FieldComponentDTO.FieldComponentId = Guid.NewGuid(); // OR let DB handle NEWID() FieldComponentDTO.CreatedById = LoginDTO.UserId; FieldComponentDTO.CreatedOn = DateTime.UtcNow; await _FieldComponentDAL.SaveFieldComponent(FieldComponentDTO, LoginDTO); return $"Details saved successfully with FieldComponent Id {FieldComponentDTO.FieldComponentId}."; } // UPDATE FieldComponent else { await _FieldComponentDAL.UpdateFieldComponent(FieldComponentDTO, LoginDTO); return $"Details updated successfully with FieldComponent Id {FieldComponentDTO.FieldComponentId}."; } } catch (ValidationException) { throw; } catch (Exception) { throw; } } public async Task GetSelectListFieldComponent(CriteriaDTO criteriaDTO, LoginDTO LoginDTO) { try { return await _FieldComponentDAL.GetSelectListFieldComponent(criteriaDTO, LoginDTO); } catch (Exception) { throw; } } public async Task DeleteFieldComponent(Guid FieldComponentId, LoginDTO LoginDTO) { try { return await _FieldComponentDAL.DeleteFieldComponent(FieldComponentId, LoginDTO); } catch (Exception) { throw; } } } }