using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using FrameworkDAL.DTO.Entity; using FrameworkDAL.Query.EntityRelation; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.Validation; using Newtonsoft.Json; namespace FrameworkDAL.CustomCode.EntityRelation { public class EntityRelationDAL : IEntityRelationDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public EntityRelationDAL(IQueryExecutor IQueryExecutor, IValidation IValidation) { _QueryExecutor = IQueryExecutor; _Validation = IValidation; } public async Task GetEntityRelation(int EntityRelationId, LoginDTO LoginDTO) { try { string sql = EntityRelationQB.GET_ENTITYRELATION; var parameters = new { entityrelationid = EntityRelationId }; EntityRelationDTO EntityRelationDTO = await _QueryExecutor.QuerySingleAsync(LoginDTO, sql, parameters); return JsonConvert.SerializeObject(EntityRelationDTO); } catch (Exception) { throw; } } public async Task SaveEntityRelation(EntityRelationDTO EntityRelationDTO, LoginDTO LoginDTO) { try { string Sql = EntityRelationQB.SAVE_ENTITYRELATION; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, EntityRelationDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.SaveErrorMessage}"); throw new Exception(Error); } } public async Task UpdateEntityRelation(EntityRelationDTO EntityRelationDTO, LoginDTO LoginDTO) { try { string Sql = EntityRelationQB.UPDATE_ENTITYRELATION; return await _QueryExecutor.ExecuteAsync(LoginDTO, Sql, EntityRelationDTO); } catch (Exception ex) { string Error = await _Validation.HandleException(ex, $"{ErrorResponse.UpdateErrorMessage}"); throw new Exception(Error); } } public async Task DeleteEntityRelation(int EntityRelationId, LoginDTO LoginDTO) { try { string Sql = EntityRelationQB.DELETE_ENTITYRELATION; var Parameters = new { entityrelationid = EntityRelationId }; 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); } } } }