using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.Validation; using MMDAL.DTO.InspectionArea; using MMDAL.Query.InspectionArea; using Newtonsoft.Json; namespace MMDAL.CustomCode.InspectionArea { public class InspectionAreaDAL : IInspectionAreaDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public InspectionAreaDAL(IQueryExecutor IQueryExecutor, IValidation IValidation) { _QueryExecutor = IQueryExecutor; _Validation = IValidation; } public async Task GetInspectionArea(int InspectionAreaId, LoginDTO LoginDTO) { try { string sql = InspectionAreaQB.GET_INSPECTIONAREA; var parameters = new { inspectionareaid = InspectionAreaId }; InspectionAreaDTO InspectionAreaDTO = await _QueryExecutor.QuerySingleAsync(LoginDTO, sql, parameters); return JsonConvert.SerializeObject(InspectionAreaDTO); } catch (Exception) { throw; } } public async Task SaveInspectionArea(InspectionAreaDTO InspectionAreaDTO, LoginDTO LoginDTO) { try { string Sql = InspectionAreaQB.SAVE_INSPECTIONAREA; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, InspectionAreaDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.SaveErrorMessage}"); throw new Exception(Error); } } public async Task UpdateInspectionArea(InspectionAreaDTO InspectionAreaDTO, LoginDTO LoginDTO) { try { string Sql = InspectionAreaQB.UPDATE_INSPECTIONAREA; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, InspectionAreaDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.UpdateErrorMessage}"); throw new Exception(Error); } } public async Task DeleteInspectionArea(int InspectionAreaId, LoginDTO LoginDTO) { try { string Sql = InspectionAreaQB.DELETE_INSPECTIONAREA; var Parameters = new { inspectionareaid = InspectionAreaId }; int 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); } } public async Task GetSelectListInspectionArea( int FirstNumber, int MaxResult, CriteriaDTO CriteriaDTO, LoginDTO LoginDTO, bool IsCount = false) { try { string Json = ""; if (!IsCount) { string Sql = InspectionAreaQB.GET_SELECTLIST_INSPECTIONAREA; var Parameters = new { firstnumber = FirstNumber, maxresult = MaxResult }; IEnumerable InspectionAreaDTO = await _QueryExecutor.QueryAsync( LoginDTO, Sql, Parameters); Json = JsonConvert.SerializeObject(InspectionAreaDTO); } else { int Count = 0; Json = Count.ToString(); } return Json; } catch (Exception) { throw; } } } }