using FrameworkDAL.DTO.Location; using FrameworkDAL.Query.Location; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.ResponseStandard; using GB5Shared.Validation; using Microsoft.VisualBasic; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Threading.Tasks; namespace FrameworkDAL.CustomCode.Location { public class LocationDAL : ILocationDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public LocationDAL(IQueryExecutor QueryExecutor, IValidation IValidation) { _QueryExecutor = QueryExecutor; _Validation = IValidation; } public async Task GetLocation(int LocationId, LoginDTO LoginDTO) { string json = ""; try { string sql = LocationQB.GET_LOCATION; var parameters = new { locationid = LocationId }; LocationDTO LocationDTOs = await _QueryExecutor.QuerySingleAsync(LoginDTO, sql, parameters); json = JsonConvert.SerializeObject(LocationDTOs); return json; } catch (Exception) { throw; } finally { json = null; } } public async Task SaveLocation(LocationDTO LocationDTO, LoginDTO LoginDTO) { try { string Sql = LocationQB.SAVE_LOCATION; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, LocationDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.SaveErrorMessage}"); throw new Exception(Error); } } public async Task UpdateLocation(LocationDTO LocationDTO, LoginDTO LoginDTO) { try { string Sql = LocationQB.UPDATE_LOCATION; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, LocationDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.UpdateErrorMessage}"); throw new Exception(Error); } } public async Task DeleteLocation(int LocationId, LoginDTO LoginDTO) { try { string Sql = LocationQB.DELETE_LOCATION; var Parameters = new { locationid = LocationId }; 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 GetSelectListLocation(int FirstNumber, int MaxResult, CriteriaDTO CriteriaDTO, LoginDTO LoginDTO, bool IsCount = false) { try { string Json = ""; if (IsCount == false) { string SQL = LocationQB.GET_SELECTLIST_LOCATION; var parameter = new { firstnumber = FirstNumber, maxresult = MaxResult }; List LocationPicklistDTO = (await _QueryExecutor.QueryAsync(LoginDTO, SQL, parameter)).ToList(); Json = JsonConvert.SerializeObject(LocationPicklistDTO); } else { int Count = 0; Json = Count.ToString(); } return Json; } catch (Exception) { throw; } } } }