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.Color; using MMDAL.Query.Color; using Newtonsoft.Json; namespace MMDAL.CustomCode.Color { public class ColorDAL: IColorDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public ColorDAL(IQueryExecutor IQueryExecutor, IValidation IValidation) { _QueryExecutor = IQueryExecutor; _Validation = IValidation; } public async Task GetColor(int ColorId, LoginDTO LoginDTO) { try { string sql = ColorQB.GET_COLOR; var parameters = new { colorid = ColorId }; ColorDTO ColorDTO = await _QueryExecutor.QuerySingleAsync(LoginDTO, sql, parameters); return JsonConvert.SerializeObject(ColorDTO); } catch (Exception) { throw; } } public async Task SaveColor(ColorDTO ColorDTO, LoginDTO LoginDTO) { try { string Sql = ColorQB.SAVE_COLOR; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, ColorDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.SaveErrorMessage}"); throw new Exception(Error); } } public async Task UpdateColor(ColorDTO ColorDTO, LoginDTO LoginDTO) { try { string Sql = ColorQB.UPDATE_COLOR; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, ColorDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.UpdateErrorMessage}"); throw new Exception(Error); } } public async Task DeleteColor(int ColorId, LoginDTO LoginDTO) { try { string Sql = ColorQB.DELETE_COLOR; var Parameters = new { colorid = ColorId }; 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 GetSelectListColor(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { string SQL = ColorQB.GET_SELECTLIST_COLOR; var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, null!); string Json = JsonConvert.SerializeObject(Result); return Json; } catch (Exception) { throw; } } } }