using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.Validation; using MMDAL.DTO.NDTMethod; using MMDAL.Query.NDTMethod; using Newtonsoft.Json; namespace MMDAL.CustomCode.NDTMethod { public class NDTMethodDAL : INDTMethodDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public NDTMethodDAL(IQueryExecutor QueryExecutor, IValidation Validation) { _QueryExecutor = QueryExecutor; _Validation = Validation; } public async Task GetNDTMethod(int NDTMethodId, LoginDTO LoginDTO) { try { string sql = NDTMethodQB.GET_NDTMETHOD; var parameters = new { ndtmethodid = NDTMethodId, tenantid = LoginDTO.ClientId }; NDTMethodDTO ndtMethodDTO = await _QueryExecutor.QuerySingleAsync( LoginDTO, sql, parameters); return JsonConvert.SerializeObject(ndtMethodDTO); } catch (Exception) { throw; } } public async Task GetSelectListNDTMethod(int FirstNumber, int MaxResult, CriteriaDTO CriteriaDTO, LoginDTO LoginDTO, bool IsCount = false) { try { if (IsCount == false) { string sql = NDTMethodQB.GET_SELECTLIST_NDTMETHOD; var parameters = new { firstnumber = FirstNumber, maxresult = MaxResult, tenantid = LoginDTO.ClientId }; var result = await _QueryExecutor.QueryAsync(LoginDTO, sql, parameters); return JsonConvert.SerializeObject(result); } else { return 0.ToString(); } } catch (Exception) { throw; } } public async Task SaveNDTMethod(NDTMethodDTO NDTMethodDTO, LoginDTO LoginDTO) { try { var parameters = new { NDTMethodDTO.NDTMethodId, NDTMethodDTO.NDTMethodCode, NDTMethodDTO.NDTMethodName, NDTMethodDTO.NDTMethodReportTitleTemplate, NDTMethodDTO.NDTMethodParameterSet, NDTMethodDTO.NDTMethodHasStartEndTime, NDTMethodDTO.NDTMethodRequiresCalibration, NDTMethodDTO.NDTMethodRemarks, NDTMethodDTO.NDTMethodSortOrder, NDTMethodDTO.NDTMethodStatus, NDTMethodDTO.NDTMethodVersion, NDTMethodDTO.NDTMethodSourceType, NDTMethodDTO.NDTMethodCreatedById, NDTMethodDTO.NDTMethodCreatedOn, NDTMethodDTO.NDTMethodModifiedById, NDTMethodDTO.NDTMethodModifiedOn, tenantid = LoginDTO.ClientId }; return await _QueryExecutor.ExecuteAsync(LoginDTO, NDTMethodQB.SAVE_NDTMETHOD, parameters); } catch (Exception ex) { string error = await _Validation.HandleException(ex, $"{ErrorResponse.SaveErrorMessage}"); throw new Exception(error); } } public async Task UpdateNDTMethod(NDTMethodDTO NDTMethodDTO, LoginDTO LoginDTO) { try { var parameters = new { NDTMethodDTO.NDTMethodId, NDTMethodDTO.NDTMethodCode, NDTMethodDTO.NDTMethodName, NDTMethodDTO.NDTMethodReportTitleTemplate, NDTMethodDTO.NDTMethodParameterSet, NDTMethodDTO.NDTMethodHasStartEndTime, NDTMethodDTO.NDTMethodRequiresCalibration, NDTMethodDTO.NDTMethodRemarks, NDTMethodDTO.NDTMethodSortOrder, NDTMethodDTO.NDTMethodStatus, NDTMethodDTO.NDTMethodVersion, NDTMethodDTO.NDTMethodSourceType, NDTMethodDTO.NDTMethodModifiedById, NDTMethodDTO.NDTMethodModifiedOn, tenantid = LoginDTO.ClientId }; return await _QueryExecutor.ExecuteAsync(LoginDTO, NDTMethodQB.UPDATE_NDTMETHOD, parameters); } catch (Exception ex) { string error = await _Validation.HandleException(ex, $"{ErrorResponse.UpdateErrorMessage}"); throw new Exception(error); } } public async Task DeleteNDTMethod(int NDTMethodId, LoginDTO LoginDTO) { try { string sql = NDTMethodQB.DELETE_NDTMETHOD; var parameters = new { ndtmethodid = NDTMethodId, tenantid = LoginDTO.ClientId }; var result = await _QueryExecutor.ExecuteAsync(LoginDTO, sql, parameters); if (result > 0) return $"{SuccessResponse.DeleteSuccessMessage}"; else return $"{ErrorResponse.DeleteNotFoundMessage}"; } catch (Exception ex) { string error = await _Validation.HandleException(ex, $"{ErrorResponse.DeleteErrorMessage}"); throw new Exception(error); } } } }