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.PriceCategory; using MMDAL.Query.PriceCategory; using Newtonsoft.Json; namespace MMDAL.CustomCode.PriceCategory { public class PriceCategoryDAL : IPriceCategoryDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public PriceCategoryDAL(IQueryExecutor IQueryExecutor,IValidation Validation) { _QueryExecutor = IQueryExecutor; _Validation = Validation; } public async Task GetSelectListPriceCategory(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { string SQL = PriceCategoryQB.GET_SELECTLIST_PRICECATEGORY; var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, null!); string Json = JsonConvert.SerializeObject(Result); return Json; } catch (Exception) { throw; } } public async Task GetPriceCategory(int PriceCategoryId, LoginDTO LoginDTO) { try { string sql = PriceCategoryQB.GET_PRICECATEGORY; var parameters = new { pricecategoryid = PriceCategoryId }; PriceCategoryDTO PriceCategoryDTOs = await _QueryExecutor.QuerySingleAsync(LoginDTO, sql, parameters); return PriceCategoryDTOs; } catch (Exception) { throw; } } public async Task SavePriceCategory(PriceCategoryDTO PriceCategoryDTO, LoginDTO LoginDTO) { try { const string Sql = PriceCategoryQB.SAVE_PRICECATEGORY; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, PriceCategoryDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.SaveErrorMessage}"); throw new Exception(Error); } } public async Task UpdatePriceCategory(PriceCategoryDTO PriceCategoryDTO, LoginDTO LoginDTO) { try { const string Sql = PriceCategoryQB.UPDATE_PRICECATEGORY; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, PriceCategoryDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.UpdateErrorMessage}"); throw new Exception(Error); } } public async Task DeletePriceCategory(int PriceCategoryId, LoginDTO LoginDTO) { try { string Sql = PriceCategoryQB.DELETE_PRICECATEGORY; var parameter = new { pricecategoryid = PriceCategoryId }; 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); } } } }