예제 #1
0
        public IActionResult Index(int page = 1)
        {
            List <MuseumInfoVM> list = museumRepository.GetShortDescription();

            const int PageSize = 12;
            var       count    = list.Count();

            if (page == 1)
            {
                list = list.Skip(0).Take(PageSize).ToList();
            }

            else
            {
                list = list.Skip((page - 1) * PageSize).Take(PageSize).ToList();
            }

            if (count <= PageSize)
            {
                ViewBag.MaxPage = 1;
            }
            else
            {
                if (count % PageSize == 0)
                {
                    ViewBag.MaxPage = (count / PageSize);
                }
                else
                {
                    ViewBag.MaxPage = (count / PageSize) + 1;
                }
            }
            ViewBag.Page     = page;
            ViewBag.NextPage = page + 1;

            foreach (MuseumInfoVM x in list)
            {
                x.Image = imageRepository.GetMuseumImage(x.Id);
                if (x.Image != null)
                {
                    x.ImageId = x.Image.Id;
                }
            }
            return(View(list));
        }