using FrameworkDAL.DTO.Country; using FrameworkDAL.Query.Country; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.ResponseStandard; using GB5Shared.Validation; using Newtonsoft.Json; using Microsoft.SqlServer.Types; using System.Data.SqlTypes; namespace FrameworkDAL.CustomCode.Country { public class CountryDAL : ICountryDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public CountryDAL(IQueryExecutor QueryExecutor, IValidation IValidation) { _QueryExecutor = QueryExecutor; _Validation = IValidation; } public async Task GetCountry(int countryId, LoginDTO LoginDTO) { string Json = ""; try { string sql = CountryQB.GET_COUNTRY; var parameters = new { countryid = countryId }; CountryDTO CountryDTOs = await _QueryExecutor.QuerySingleAsync(LoginDTO, sql, parameters); Json = JsonConvert.SerializeObject(CountryDTOs); return Json; } catch (Exception) { throw; } finally { Json = null; } } public async Task GetSelectListCountry(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { string SQL = CountryQB.GET_SELECTLIST_COUNTRY; var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, null!); string Json = JsonConvert.SerializeObject(Result); return Json; } catch (Exception) { throw; } } public async Task SaveCountry(CountryDTO CountryDTO, LoginDTO LoginDTO) { try { string Sql = CountryQB.SAVE_COUNTRY; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, CountryDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.SaveErrorMessage}"); throw new Exception(Error); } } public async Task UpdateCountry(CountryDTO CountryDTO, LoginDTO LoginDTO) { try { string Sql = CountryQB.UPDATE_COUNTRY; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, CountryDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.UpdateErrorMessage}"); throw new Exception(Error); } } public async Task DeleteCountry(int CountryId, LoginDTO LoginDTO) { try { string Sql = CountryQB.DELETE_COUNTRY; var parameter = new { countryid = CountryId }; 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); } } } }