using AdminDAL.DTO.Period; using AdminDAL.Query.Period; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Logging; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.ResponseStandard; using GB5Shared.Resource.Response; using GB5Shared.Validation; using Microsoft.Data.SqlClient; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace AdminDAL.CustomCode.Period { public class PeriodDAL : IPeriodDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public PeriodDAL(IQueryExecutor IQueryExecutor, IValidation IValidation) { _QueryExecutor = IQueryExecutor; _Validation = IValidation; } public async Task GetPeriod(int PeriodId, LoginDTO LoginDTO) { try { string sql = PeriodQB.GET_PERIOD; var parameters = new { periodid = PeriodId }; PeriodDTO PeriodDTO = await _QueryExecutor.QuerySingleAsync(LoginDTO, sql, parameters); return JsonConvert.SerializeObject(PeriodDTO); } catch (Exception) { throw; } } public async Task SavePeriod(PeriodDTO PeriodDTO, LoginDTO LoginDTO) { try { string Sql = PeriodQB.SAVE_PERIOD; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, PeriodDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.SaveErrorMessage}"); throw new Exception(Error); } } public async Task UpdatePeriod(PeriodDTO PeriodDTO, LoginDTO LoginDTO) { try { string Sql = PeriodQB.UPDATE_PERIOD; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, PeriodDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.UpdateErrorMessage}"); throw new Exception(Error); } } public async Task DeletePeriod(int PeriodId, LoginDTO LoginDTO) { try { string Sql = PeriodQB.DELETE_PERIOD; var Parameters = new { periodid = PeriodId }; 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 GetSelectListPeriod(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { string SQL = PeriodQB.GET_SELECTLIST_PERIOD; var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, null!); string Json = JsonConvert.SerializeObject(Result); return Json; } catch (Exception) { throw; } } } }