public override IResult <T> Execute(IContext dataContext) { var query = dataContext.AsQueryable <T>(); if (IncludeQuery != null) { query = IncludeQuery.Include(query); } foreach (var queryFilter in QueryFilters) { query = queryFilter.Filter(query); } var data = Filter != null ? query.FirstOrDefault(Filter) : query.FirstOrDefault(); if (data == null) { return(new Result <T>( //errorCode: ValidationCodes.Common.Cmn021, entityName: typeof(T).Name.SplitCamelCase())); } return(new Result <T>(data)); }
public override IListResult <TEntity> Execute(IContext dataContext) { var query = dataContext.AsQueryable <TEntity>(); if (QueryInclude != null) { query = QueryInclude.Include(query); } foreach (var queryFilter in QueryFilters) { query = queryFilter.Filter(query); } if (Filter != null) { query = query.Where(Filter); } var total = query.Count(); var data = query.SortAndPage(SortDictionary, Request); return(new ListResult <TEntity>(data.ToList(), Request) { Total = total }); }
public override IResult <T> Execute(IContext dataContext) { if (string.IsNullOrEmpty(Request.Email)) { return new Result <T> { Status = HttpStatusCode.BadRequest } } ; string email = Request.Email.Trim().ToLowerInvariant(); var entity = dataContext.AsQueryable <T>() .FirstOrDefault(x => x.IsActive && !string.IsNullOrEmpty(x.Email) && x.Email.ToLower() == email); if (entity == null) { return new Result <T> { Status = HttpStatusCode.NotFound } } ; return(new Result <T>(entity)); } } }
public override IResult <HistoryData> Execute(IContext dataContext) { string tableName = typeof(T).Name.ToPostgreConvention().ToPlural(); var result = dataContext.AsQueryable <HistoryData>().Where(x => x.TableName == tableName && x.Id == Request.Id).FirstOrDefault(); return(new Result <HistoryData>(result) { Status = result == null ? HttpStatusCode.NotFound : HttpStatusCode.OK }); }
public override IResult <bool> Execute(IContext dataContext) { var query = dataContext.AsQueryable <T>(); if (QueryInclude != null) { query = QueryInclude.Include(query); } return(_invertPredicate ? new Result <bool>(!query.Any(Predicate)) : new Result <bool>(query.Any(Predicate))); }
public override IResult <bool> Execute(IContext dataContext) { if (_select == null) { throw new ArgumentNullException(nameof(_select)); } if (_queryInclude == null) { throw new ArgumentNullException(nameof(_queryInclude)); } var query = dataContext.AsQueryable <T>(); if (_queryInclude != null) { query = _queryInclude(query); } if (Predicate != null) { query = query.Where(Predicate); } var entities = query.SelectMany(_select).ToList(); foreach (var entity in entities) { if (!Request.SetParent && (entity.IsActive) == Request.IsActive) { return(new Result <bool>( //errorCode: Request.IsActive ? ValidationCodes.Common.Cmn022 : ValidationCodes.Common.Cmn023, entityName: typeof(T).Name.SplitCamelCase())); } entity.IsActive = Request.IsActive; entity.UpdateAuditableProperties( Request.IsActive ? AuditableEntity.AuditableAction.Reactivate : AuditableEntity.AuditableAction.Delete, UserId); } dataContext.UpdateMultiple(entities); return(new Result <bool> { Value = true }); }
public override IResult <T> Execute(IContext dataContext) { var entity = dataContext.AsQueryable <T>().FirstOrDefault(x => x.Id == Request.Id); if (entity == null) { return(new Result <T>(errorCode: ValidationCodes.Common.Cmn008, entityName: typeof(T).Name.SplitCamelCase())); } var updateResponse = Update(dataContext, entity); if (updateResponse.Status != HttpStatusCode.OK) { return(new Result <T>(HttpStatusCode.InternalServerError, ValidationCodes.Common.Cmn046)); } return(new Result <T>(entity)); }
public override IResult <long> Execute(IContext dataContext) { var query = dataContext.AsQueryable <T>(); if (IncludeQuery != null) { query = IncludeQuery.Include(query); } var entity = !Request.IsNew ? Queryable.FirstOrDefault(query, x => x.Id == Request.Id) : new T(); if (entity == null) { return(new Result <long>( // errorCode: ValidationCodes.Common.Cmn021, entityName: typeof(T).Name.SplitCamelCase())); } MapAction?.Invoke(entity, WrappedRequest); entity.UpdateAuditableProperties(Request.IsNew ? AuditableEntity.AuditableAction.Insert : AuditableEntity.AuditableAction.Update, UserId); //if (entity.AlternateId==0) if (Request.IsNew) { dataContext.InsertWithChildEntities(entity); } else { dataContext.Update(entity); } return(new Result <long> { Value = entity.Id }); }