using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; 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; using MMDAL.CustomCode.Shape; using MMDAL.DTO.Shape; namespace MMBLL.Shape { public class ShapeBLL : IShapeBLL { private readonly IShapeDAL _ShapeDAL; private readonly AutoNumber _AutoNumber; private readonly IValidation _Validation; public ShapeBLL(IShapeDAL IShapeDAL, AutoNumber AutoNumber, IValidation validation) { _ShapeDAL = IShapeDAL; _AutoNumber = AutoNumber; _Validation = validation; } public async Task GetShape(int ShapeId, LoginDTO LoginDTO) { try { return await _ShapeDAL.GetShape(ShapeId, LoginDTO); } catch (Exception) { throw; } } public async Task GetSelectListShape(int FirstNumber, int MaxResult, CriteriaDTO criteriaDTO, LoginDTO LoginDTO) { try { return await _ShapeDAL.GetSelectListShape(FirstNumber, MaxResult, criteriaDTO, LoginDTO); } catch (Exception) { throw; } } public async Task SaveShape(ShapeDTO ShapeDTO, LoginDTO LoginDTO) { if (ShapeDTO == null) throw new ArgumentNullException(nameof(ShapeDTO)); try { await _Validation.NotEmpty(ShapeDTO.ShapeCode, nameof(ShapeDTO.ShapeCode)); await _Validation.NotEmpty(ShapeDTO.ShapeName, nameof(ShapeDTO.ShapeName)); ShapeDTO.ShapeModifiedById = LoginDTO.UserId; ShapeDTO.ShapeModifiedOn = DateTime.UtcNow; int initialId = ShapeDTO.ShapeId; int count = 1 + initialId; if (initialId == 0) { ShapeDTO.ShapeCreatedById = LoginDTO.UserId; ShapeDTO.ShapeCreatedOn = DateTime.UtcNow; await _ShapeDAL.SaveShape(ShapeDTO, LoginDTO); return $"{SuccessResponse.SaveSuccessName} {ShapeDTO.ShapeName}"; } else { await _ShapeDAL.UpdateShape(ShapeDTO, LoginDTO); return $"{SuccessResponse.UpdateSuccessName} {ShapeDTO.ShapeName}"; } } catch (ValidationException vex) { throw new Exception(vex.Message); } } public async Task DeleteShape(int ShapeId, LoginDTO LoginDTO) { try { return await _ShapeDAL.DeleteShape(ShapeId, LoginDTO); } catch (Exception) { throw; } } } }