using MMDAL.CustomCode.InspectionParameter; using MMDAL.DTO.Inspection; 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 System; using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; namespace MMBLL.InspectionParameter { public class InspectionParameterBLL : IInspectionParameterBLL { private readonly IInspectionParameterDAL _InspectionParameterDAL; private readonly AutoNumber _AutoNumber; private readonly IValidation _Validation; public InspectionParameterBLL( IInspectionParameterDAL InspectionParameterDAL, AutoNumber AutoNumber, IValidation Validation) { _InspectionParameterDAL = InspectionParameterDAL; _AutoNumber = AutoNumber; _Validation = Validation; } public async Task GetInspectionParameter(int InspectionParameterId, LoginDTO LoginDTO) { try { return await _InspectionParameterDAL.GetInspectionParameter(InspectionParameterId, LoginDTO); } catch (Exception) { throw; } } public async Task SaveInspectionParameter( InspectionParameterDTO InspectionParameterDTO, LoginDTO LoginDTO) { //if (InspectionParameterDTO == null) throw new ArgumentNullException(nameof(InspectionParameterDTO)); //AutoNumberDTO? autoNumberDTO = null; try { if (InspectionParameterDTO.InspectionParameterId == 0) { //autoNumberDTO = await _AutoNumber.GetAutoNumber(count, "InspectionParameter", LoginDTO); //InspectionParameterDTO.InspectionParameterId = autoNumberDTO.StartNumber; await _InspectionParameterDAL.SaveInspectionParameter( InspectionParameterDTO, LoginDTO); return $"{SuccessResponse.SaveSuccess}"; } else { await _InspectionParameterDAL.UpdateInspectionParameter( InspectionParameterDTO, LoginDTO); return $"{SuccessResponse.UpdateSuccess}"; } } catch (ValidationException vex) { throw new Exception(vex.Message); } catch (Exception) { //if (autoNumberDTO != null && InspectionParameterDTO.InspectionParameterId > 0) // await _AutoNumber.RollbackAutoNumber( // "InspectionParameter", // InspectionParameterDTO.InspectionParameterId, // LoginDTO); throw; } } public async Task GetSelectListInspectionParameter( int FirstNumber, int MaxResult, CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { return await _InspectionParameterDAL.GetSelectListInspectionParameter( FirstNumber, MaxResult, CriteriaDTO, LoginDTO); } catch (Exception) { throw; } } public async Task DeleteInspectionParameter( int InspectionParameterId, LoginDTO LoginDTO) { try { return await _InspectionParameterDAL.DeleteInspectionParameter( InspectionParameterId, LoginDTO); } catch (Exception) { throw; } } public async Task GetInspectionParameterList( CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { return await _InspectionParameterDAL.GetInspectionParameterList( CriteriaDTO, LoginDTO); } catch (Exception) { throw; } } } }