Exemple #1
0
        public async Task <IActionResult> GetObjectTags([FromRoute] int category_id, int count = 20, int page = 0)
        {
            var category = await _context.IncludeCategoryContext()
                           .FirstOrDefaultAsync(c => c.Id == category_id);

            if (category == null)
            {
                return(NotFound());
            }

            var temp = new PaginationItem <ObjectTagResponse>();

            temp.TotalCount = category.ObjectTags.Count();

            // トータルページ数
            temp.TotalPage = (temp.TotalCount - 1) / count;
            if (temp.TotalPage < page)
            {
                temp.CurrentPage = 0;
            }
            else
            {
                temp.CurrentPage = page;
            }

            temp.Items = category.ObjectTags
                         .Skip((temp.CurrentPage) * count)
                         .Take(count)
                         .Select(c => c.ToApiModel())
                         .ToList();
            return(Ok(temp));
        }
Exemple #2
0
        public async Task <IActionResult> GetUsers(int count = 20, int page = 0)
        {
            var users = _context.Users;

            var temp = new PaginationItem <UserInfoResponse>();

            temp.TotalCount = users.Count();

            // トータルページ数
            temp.TotalPage = (temp.TotalCount - 1) / count;
            if (temp.TotalPage < page)
            {
                temp.CurrentPage = 0;
            }
            else
            {
                temp.CurrentPage = page;
            }

            temp.Items = users.Skip((temp.CurrentPage) * count)
                         .Take(count)
                         .Select(c => c.ToApiModel())
                         .ToList();
            return(Ok(temp));
        }
Exemple #3
0
        public async Task <IActionResult> SearchCategories(string[] keywords = null, int count = 20, int page = 0)
        {
            var items = _context.IncludeCategoryContext().Select(c => c);

            if (keywords != null)
            {
                foreach (var keyword in keywords)
                {
                    items = items.Where(c => c.Name.Contains(keyword) || c.Description.Contains(keyword));
                }
            }

            var temp = new PaginationItem <CategoryResponse>();

            temp.TotalCount = items.Count();

            // トータルページ数
            temp.TotalPage = (temp.TotalCount - 1) / count;
            if (temp.TotalPage < page)
            {
                temp.CurrentPage = 0;
            }
            else
            {
                temp.CurrentPage = page;
            }

            temp.Items = items.Skip((temp.CurrentPage) * count)
                         .Take(count)
                         .Select(c => c.ToApiModel())
                         .ToList();
            return(Ok(temp));
        }
Exemple #4
0
        public Paginator(string relativeUrl, int totalNumOfPages, int currentPageNum, int numOfAdjacentLinksToDisplay)
        {
            var leftShowableLink  = currentPageNum - numOfAdjacentLinksToDisplay;
            var rightShowableLink = currentPageNum + numOfAdjacentLinksToDisplay;

            // Possible 'Previous' link.
            if (currentPageNum > 1)
            {
                _paginationItems.Add(new PreviousLink(relativeUrl, (currentPageNum - 1)));
            }

            // Always add first page link.
            _paginationItems.Add(new PageLink(relativeUrl, 1, (currentPageNum == 1)));

            // Possible left-side ellipse.
            if ((leftShowableLink - 1) > 1)
            {
                _paginationItems.Add(new Ellipse());
            }

            // Add displayable links.
            for (var pageNum = leftShowableLink < 2 ? 2 : leftShowableLink;
                 pageNum <= rightShowableLink && pageNum < totalNumOfPages;
                 pageNum++)
            {
                _paginationItems.Add(new PageLink(relativeUrl, pageNum, (currentPageNum == pageNum)));
            }

            // Possible right-side ellipse.
            if ((totalNumOfPages - rightShowableLink) > 1)
            {
                _paginationItems.Add(new Ellipse());
            }

            // Always add last page link.
            if (totalNumOfPages > 1)
            {
                _paginationItems.Add(new PageLink(relativeUrl, totalNumOfPages, (currentPageNum == totalNumOfPages)));
            }

            // Possible 'Next' link.
            if (currentPageNum < totalNumOfPages)
            {
                _paginationItems.Add(new NextLink(relativeUrl, (currentPageNum + 1)));
            }



            // Head pagination *rel* tags.
            _prevTag = currentPageNum != 1
        ? String.Format("<link rel=\"prev\" href=\"{0}\" />",
                        PaginationItem.MakeUrlPath(relativeUrl, (currentPageNum - 1)))
        : String.Empty;

            _nextTag = currentPageNum != totalNumOfPages
        ? String.Format("<link rel=\"next\" href=\"{0}\" />",
                        PaginationItem.MakeUrlPath(relativeUrl, (currentPageNum + 1)))
        : String.Empty;
        }
Exemple #5
0
        /*Populates book items*/
        public static void AddBooks(VBSContext context)
        {
            var isbn   = "123456";
            var title  = "This is the title of book #";
            var genres = new List <string>()
            {
                "male", "female"
            };
            var synopsis = "This book is the book #";
            var value    = 20;

            var books      = new List <BookItem>();
            var pagination = new PaginationItem();

            pagination.Limit  = 40;
            pagination.Offset = 20;
            pagination.Total  = 1000;

            for (int i = 0; i < 10; i++)
            {
                // Select the genre according to current index
                var index = (i % 2) == 0? 0 : 1;

                BookItem book = new BookItem()
                {
                    Isbn       = isbn + i,
                    Title      = title + i,
                    Genre      = genres[index],
                    Synopsis   = synopsis + i,
                    Value      = (long)value / (i + 1),
                    Pagination = pagination
                };

                context.BookItems.Add(book);
            }

            context.SaveChanges();
        }
Exemple #6
0
        public IActionResult GetCategories(int count = 20, int page = 0)
        {
            var temp   = new PaginationItem <CategoryResponse>();
            var source = _context.Categories.Where(c => c.Name != "");

            temp.TotalCount = source.Count();

            // トータルページ数
            temp.TotalPage = (temp.TotalCount - 1) / count;
            if (temp.TotalPage < page)
            {
                temp.CurrentPage = 0;
            }
            else
            {
                temp.CurrentPage = page;
            }

            temp.Items = source.Skip(temp.CurrentPage * count)
                         .Take(count)
                         .Select(c => c.ToApiModel())
                         .ToList();
            return(Ok(temp));
        }
Exemple #7
0
        public async Task <IActionResult> SearchReservations(
            string object_tag_id = null,
            string user_name     = null,
            string[] keywords    = null,
            DateTime?since_at    = null,
            DateTime?to_at       = null,
            bool includes_past   = false,
            int count            = 20, int page = 0)
        {
            var items = _context.IncludeReservationContext().Select(c => c);

            if (object_tag_id != null)
            {
                items = items.Where(c => c.ObjectTagId == object_tag_id);
            }

            if (user_name != null)
            {
                var user = await _context.Users.FirstOrDefaultAsync(c => c.UserName == user_name);

                if (user != null)
                {
                    items =
                        items.Where(c => c.OwnerUserId == user.Id || c.ReservationUsers.Any(m => m.UserId == user.Id));
                }
            }

            if (keywords != null)
            {
                foreach (var keyword in keywords)
                {
                    items = items.Where(c => c.Comment.Contains(keyword));
                }
            }

            if (!includes_past)
            {
                items = items.FilterEnabledReservations();
            }

            if (since_at != null)
            {
                items = items.Where(c => c.IsEndless || c.EndAt.GetValueOrDefault(DateTime.MaxValue) >= since_at.Value);
            }

            if (to_at != null)
            {
                items = items.Where(c => c.IsEndless || c.StartAt <= to_at.Value);
            }

            var temp = new PaginationItem <ReservationResponse>();

            temp.TotalCount = items.Count();

            // トータルページ数
            temp.TotalPage = (temp.TotalCount - 1) / count;
            if (temp.TotalPage < page)
            {
                temp.CurrentPage = 0;
            }
            else
            {
                temp.CurrentPage = page;
            }

            temp.Items = items.Skip((temp.CurrentPage) * count)
                         .Take(count)
                         .Select(c => c.ToApiModel())
                         .ToList();
            return(Ok(temp));
        }