Beispiel #1
0
        public async Task <object> Get(Getrailers request)
        {
            var user   = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null;
            var result = await GetAllTrailers(user).ConfigureAwait(false);

            IEnumerable <BaseItem> items = result.Items;

            // Apply filters
            // Run them starting with the ones that are likely to reduce the list the most
            foreach (var filter in request.GetFilters().OrderByDescending(f => (int)f))
            {
                items = ItemsService.ApplyFilter(items, filter, user, _userDataRepository);
            }

            items = _libraryManager.Sort(items, user, request.GetOrderBy(), request.SortOrder ?? SortOrder.Ascending);

            var itemsArray = items.ToList();

            var pagedItems = ApplyPaging(request, itemsArray);

            var fields = request.GetItemFields().ToList();

            var returnItems = pagedItems.Select(i => _dtoService.GetBaseItemDto(i, fields, user)).ToArray();

            return(new ItemsResult
            {
                TotalRecordCount = itemsArray.Count,
                Items = returnItems
            });
        }
Beispiel #2
0
        public object Get(Getrailers request)
        {
            var json     = _json.SerializeToString(request);
            var getItems = _json.DeserializeFromString <GetItems>(json);

            getItems.IncludeItemTypes = "Trailer";

            return(new ItemsService(_userManager, _libraryManager, _localizationManager, _dtoService, _authContext)
            {
                Request = Request,
            }.Get(getItems));
        }
Beispiel #3
0
        public object Get(Getrailers request)
        {
            var json     = _json.SerializeToString(request);
            var getItems = _json.DeserializeFromString <GetItems>(json);

            getItems.IncludeItemTypes = "Trailer";

            return(new ItemsService(_userManager, _libraryManager, _localizationManager, _dtoService)
            {
                AuthorizationContext = AuthorizationContext,
                Logger = Logger,
                Request = Request,
                ResultFactory = ResultFactory,
                SessionContext = SessionContext
            }.Get(getItems));
        }
Beispiel #4
0
        private IEnumerable <BaseItem> ApplyPaging(Getrailers request, IEnumerable <BaseItem> items)
        {
            // Start at
            if (request.StartIndex.HasValue)
            {
                items = items.Skip(request.StartIndex.Value);
            }

            // Return limit
            if (request.Limit.HasValue)
            {
                items = items.Take(request.Limit.Value);
            }

            return(items);
        }