using AdminDAL.DTO.Allocation; using AdminDAL.Query.AllocationType; 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 System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AdminDAL.CustomCode.AllocationType { public class AllocationTypeDAL : IAllocationTypeDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public AllocationTypeDAL(IQueryExecutor QueryExecutor,IValidation validation) { _QueryExecutor = QueryExecutor; _Validation = validation; } public async Task GetSelectListAllocationType(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { string SQL = AllocationTypeQB.GET_ALLOCATIONTYPE_SELECTLIST; var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, null!); string Json = JsonConvert.SerializeObject(Result); return Json; } catch (Exception) { throw; } } public async Task GetAllocationType(int AllocationTypeId, LoginDTO LoginDTO) { string Json = ""; try { string sql = AllocationTypeQB.GET_ALLOCATIONTYPE; var parameters = new { allocationtypeid = AllocationTypeId }; AllocationTypeDTO AllocationTypeDTOs = await _QueryExecutor.QuerySingleAsync(LoginDTO, sql, parameters); Json = JsonConvert.SerializeObject(AllocationTypeDTOs); return Json; } catch (Exception) { throw; } finally { Json = null; } } public async Task SaveAllocationType(AllocationTypeDTO AllocationTypeDTO, LoginDTO LoginDTO) { try { const string Sql = AllocationTypeQB.SAVE_ALLOCATIONTYPE; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, AllocationTypeDTO); } catch (Exception ex) { throw new Exception("Error while saving AllocationType", ex); } } public async Task UpdateAllocationType(AllocationTypeDTO AllocationTypeDTO, LoginDTO LoginDTO) { try { const string sql = AllocationTypeQB.UPDATE_ALLOCATIONTYPE; return await _QueryExecutor.ExecuteAsync(LoginDTO, sql, AllocationTypeDTO); } catch (Exception ex) { throw new Exception("Error while updating AllocationType", ex); } } public async Task DeleteAllocationType(int AllocationTypeId, LoginDTO LoginDTO) { try { string sql = AllocationTypeQB.DELETE_ALLOCATIONTYPE; var parameter = new { allocationtypeid = AllocationTypeId }; 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); } } } }