public IEnumerable <T> MakePage <T>( SortedPaginationModel model, IEnumerable <T> source) { if (source is null) { return(null); } if (model.PropertyToSort is not null) { PropertyDescriptor sortProperty = TypeDescriptor.GetProperties(typeof(TEntity)).Find(model.PropertyToSort, true); if (sortProperty is null) { return(null); } source = model.SortByAscending ? source.OrderBy(x => sortProperty) : source.OrderByDescending(x => sortProperty); } return(source .Skip(model.Offset.Value) .Take(model.Count.Value)); }
public IEnumerable <TDto> MakePage( SortedPaginationModel model, IEnumerable <TEntity> source) { return(MakePage <TEntity>(model, source) .Select(e => mapper.Map <TEntity, TDto>(e))); }
public async Task <IEnumerable <ScheduledTrainingDto> > GetAllScheduledTrainins( SortedPaginationModel model, int userId) { Expression <Func <ScheduledTraining, bool> > filter = s => s.Template.CreatorId == userId; return(await paginationService.GetRangeAsync(model, filter)); }
public async Task <IEnumerable <TrainingTemplateDto> > GetTrainingTemplatesByUserIdAsync( SortedPaginationModel model, int userId) { User user = await userService.GetUserEntityByIdAsync(userId); if (user is null) { return(null); } return(paginationService.MakePage(model, user.TrainingTemplates)); }
public async Task <IEnumerable <TDto> > GetRangeAsync( SortedPaginationModel model, Expression <Func <TEntity, bool> > filter) { IQueryable <TEntity> query = repository.GetAll(); if (filter is not null) { query = query.Where(filter); } if (model.PropertyToSort is not null) { Type type = typeof(TEntity); PropertyDescriptor sortProperty = TypeDescriptor.GetProperties(typeof(TEntity)).Find(model.PropertyToSort, true); if (sortProperty is not null) { ParameterExpression paramExpr = Expression.Parameter(type); Expression <Func <TEntity, object> > expression = Expression.Lambda <Func <TEntity, object> >( Expression.Convert( Expression.Property(paramExpr, sortProperty.Name), typeof(object)), paramExpr); query = model.SortByAscending ? query.OrderBy(expression) : query.OrderByDescending(expression); } } return(await query .Skip(model.Offset.Value) .Take(model.Count.Value) .Select(e => mapper.Map <TEntity, TDto>(e)) .ToListAsync()); }
public async Task <IEnumerable <TrainingHistoryDto> > GetAllTrainingHistoriesAsync(SortedPaginationModel model) { return(await paginationService.GetRangeAsync(model)); }
public async Task <IActionResult> GetCategoriesAll([FromQuery] SortedPaginationModel model) { return(this.ConvertResult(await trainingCategoryService.GetAllAsync(model))); }
public async Task <IActionResult> GetTrainingTemplatesAsync([FromQuery] SortedPaginationModel model) { return(this.ConvertResult( await trainingTemplateService.GetTrainingTemplatesByUserIdAsync(model, userResolverService.GetUserId()))); }
public async Task <IActionResult> GetAllTrainingSchedules([FromQuery] SortedPaginationModel model) { return(this.ConvertResult( await scheduledTrainingService.GetAllScheduledTrainins(model, userResolverService.GetUserId()))); }
public async Task <IActionResult> GetOutputRequestsAsync([FromQuery] SortedPaginationModel model) { return(this.ConvertResult( await friendRequestService.GetOutputFriendRequestsAsync(model, userResolverService.GetUserId()))); }
public async Task <IEnumerable <FriendRequestDto> > GetInputFriendRequestsAsync(SortedPaginationModel model, int userId) { Expression <Func <FriendRequest, bool> > filter = f => f.RequestToId.Equals(userId); return(await paginationService.GetRangeAsync(model, filter)); }