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.Defect; using MMDAL.Query.Defect; using Newtonsoft.Json; namespace MMDAL.CustomCode.Defect { public class DefectDAL : IDefectDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public DefectDAL(IQueryExecutor QueryExecutor, IValidation validation) { _QueryExecutor = QueryExecutor; _Validation = validation; } public async Task GetDefect(int DefectId, LoginDTO LoginDTO) { string Json = ""; try { string sql = DefectQB.GET_DEFECT; var parameters = new { defectid = DefectId }; DefectDTO EventyTypeDTOs = await _QueryExecutor.QuerySingleAsync(LoginDTO, sql, parameters); Json = JsonConvert.SerializeObject(EventyTypeDTOs); return Json; } catch (Exception) { throw; } finally { Json = null; } } public async Task GetSelectListDefect(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { string SQL = DefectQB.GET_SELECTLIST_DEFECT; var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, null!); string Json = JsonConvert.SerializeObject(Result); return Json; } catch (Exception) { throw; } } public async Task SaveDefect(DefectDTO DefectDTO, LoginDTO LoginDTO) { try { const string Sql = DefectQB.SAVE_DEFECT; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, DefectDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.SaveErrorMessage}"); throw new Exception(Error); } } public async Task UpdateDefect(DefectDTO DefectDTO, LoginDTO LoginDTO) { try { const string Sql = DefectQB.UPDATE_DEFECT; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, DefectDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.UpdateErrorMessage}"); throw new Exception(Error); } } public async Task DeleteDefect(int DefectId, LoginDTO LoginDTO) { try { string Sql = DefectQB.DELETE_DEFECT; var parameter = new { defectid = DefectId }; var result = await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, parameter); 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); } } } }