Esempio n. 1
0
        public async Task <IEnumerable <FileItem> > GetFileItems(string filename = null, string description = null, string filetype = null, string sort = "id", string order = "asc", int pageNo = 1, int pageSize = maxPageSize)
        {
            //Get all FileItems from a user
            FileItemSet fileItemSet = await _context.GetAllFilesUsingAPI(User.GetUserId());

            IList <FileItem> fileItems = fileItemSet.ListFileItems;

            //reset pagesize if higher than maxPageSize
            if (pageSize > maxPageSize)
            {
                pageSize = maxPageSize;
            }

            //search string
            fileItems = fileItems.Where(x => (filename == null || x.FileName.Contains(filename)))
                        .Where(x => (description == null || x.Description.Contains(description)))
                        .Where(x => (filetype == null || x.DataType.Contains(filetype))).ToList();

            //sort fileItems
            var sortedFileItems = fileItems.ApplySorting(sort, order);

            //metadata för paging
            int totalFileItems = sortedFileItems.Count;
            int totalPages     = (int)Math.Ceiling((double)totalFileItems / pageSize);

            //Previous link
            var prevPageLink = pageNo == 1 ? string.Empty : _urlHelper.Link("GetFileItems",
                                                                            new
            {
                pageNo   = pageNo - 1,
                pageSize = pageSize
            });

            //Next link
            var nextPageLink = pageNo == totalPages ? string.Empty : _urlHelper.Link("GetFileItems",
                                                                                     new
            {
                pageNo   = pageNo + 1,
                pageSize = pageSize
            });

            //page header info
            var pageHeader = new
            {
                pageNo         = pageNo,
                pageSize       = pageSize,
                totalFileItems = totalFileItems,
                totalPages     = totalPages,
                prevPageLink   = prevPageLink,
                nextPageLink   = nextPageLink
            };

            Response.Headers.Add("X-PageInfo", JsonConvert.SerializeObject(pageHeader));

            return(sortedFileItems.Skip((pageNo - 1) * pageSize).Take(pageSize));
        }
Esempio n. 2
0
        // Read (All) METADATA
        public async Task <FileItemSet> GetAllFilesUsingAPI(string userID)
        {
            var ListFileItems = await _context.FileItems.Where(x => x.UserId == userID).ToListAsync();

            FileItemSet returnFileITem = new FileItemSet()
            {
                ListFileItems = ListFileItems
            };

            return(returnFileITem);
        }