using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using CostingDAL.DTO.ResourceType; using CostingDAL.Query.ResourceType; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Logging; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.Validation; using Newtonsoft.Json; using static GB5Shared.DTO.Framework.Enum.FrameworkEnumDTO; namespace CostingDAL.CustomCode.ResourceType { public class ResourceTypeDAL : IResourceTypeDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public ResourceTypeDAL(IQueryExecutor QueryExecutor, IValidation validation) { _QueryExecutor = QueryExecutor; _Validation = validation; } public async Task GetSelectListResourceType(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO) { try { string SQL = ResourceTypeQB.GetSelectListResourceType; var Result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, null!); string Json = JsonConvert.SerializeObject(Result); return Json; } catch (Exception) { throw; } } public async Task GetResourceType(int ResourceTypeId, LoginDTO LoginDTO) { try { string SQL = ResourceTypeQB.GetResourceType; var parameters = new { resourcetypeid = ResourceTypeId }; var result = await _QueryExecutor.QueryAsync(LoginDTO, SQL, parameters); string json = JsonConvert.SerializeObject(result); return json; } catch (Exception) { throw; } } public async Task SaveResourceType(ResourceTypeDTO ResourceTypeDTO, LoginDTO LoginDTO) { try { const string Sql = ResourceTypeQB.SAVE_RESOURCETYPE; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, ResourceTypeDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.SaveErrorMessage}"); throw new Exception(Error); } } public async Task UpdateResourceType(ResourceTypeDTO ResourceTypeDTO, LoginDTO LoginDTO) { try { const string Sql = ResourceTypeQB.UPDATE_RESOURCETYPE; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, ResourceTypeDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.UpdateErrorMessage}"); throw new Exception(Error); } } public async Task DeleteResourceType(int ResourceTypeId, LoginDTO LoginDTO) { try { string Sql = ResourceTypeQB.DELETE_RESOURCETYPE; var parameter = new { resourcetypeid = ResourceTypeId }; 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); } } } }