예제 #1
0
        public async Task <PagedList <MemeVM> > GetPagedFavouritesMemesAsync
            (int page, int itemsPerPage, System.Security.Claims.ClaimsPrincipal user)
        {
            string        userId     = user.Claims.First(c => c.Type == "UserID").Value;
            var           resList    = new PagedList <MemeVM>(); //zwracany model
            List <MemeVM> list       = new List <MemeVM>();      // PagedList.Items
            var           favourites = await _favouriteService.GetAllAsync(m => m.UserId == userId);

            var favs = await _favouriteService.GetAllFilteredIncludeAsync(m => m.UserId == userId,
                                                                          x => x.MemeRefId);

            foreach (var m in favourites)
            {
                list.Add(await MapMemeVM(await _repository.FindAsync(m.MemeRefId), user));
            }


            //available pages
            resList.PageCount = (int)Math.Ceiling(((double)list.Count() / itemsPerPage));

            list = list.Skip((page - 1) * itemsPerPage).Take(itemsPerPage).ToList();

            resList.ItemsPerPage = itemsPerPage;
            resList.Page         = page;
            resList.TotalItems   = list.Count();
            resList.Items        = list;
            return(resList);
        }