예제 #1
0
        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));
        }
예제 #2
0
 public IEnumerable <TDto> MakePage(
     SortedPaginationModel model,
     IEnumerable <TEntity> source)
 {
     return(MakePage <TEntity>(model, source)
            .Select(e => mapper.Map <TEntity, TDto>(e)));
 }
예제 #3
0
        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));
        }
예제 #5
0
        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());
        }
예제 #6
0
 public async Task <IEnumerable <TrainingHistoryDto> > GetAllTrainingHistoriesAsync(SortedPaginationModel model)
 {
     return(await paginationService.GetRangeAsync(model));
 }
예제 #7
0
 public async Task <IActionResult> GetCategoriesAll([FromQuery] SortedPaginationModel model)
 {
     return(this.ConvertResult(await trainingCategoryService.GetAllAsync(model)));
 }
예제 #8
0
 public async Task <IActionResult> GetTrainingTemplatesAsync([FromQuery] SortedPaginationModel model)
 {
     return(this.ConvertResult(
                await trainingTemplateService.GetTrainingTemplatesByUserIdAsync(model, userResolverService.GetUserId())));
 }
예제 #9
0
 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())));
 }
예제 #11
0
        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));
        }