Example #1
0
        public ActionResult Index(int?page, int?cat)
        {
            string pozdrav     = "Lof lof";
            int    cislo       = 12;
            int    itemsOnPage = 2;
            int    pg          = page.HasValue ? page.Value : 1;
            int    totalBooks;


            // Potřebuju uložit do kontaineru abych to dostal do view
            ViewBag.Pozdrav = pozdrav;
            ViewBag.Cislo   = cislo;

            BookDao      bookDao = new BookDao();
            IList <Book> books   = bookDao.GetBooksPaged(itemsOnPage, pg, out totalBooks, cat);

            KnihovnaUser user = new KnihovnaUserDao().GetByLogin(User.Identity.Name);

            ViewBag.Pages       = (int)Math.Ceiling((double)totalBooks / (double)itemsOnPage);
            ViewBag.CurrentPage = pg;
            ViewBag.PerPage     = itemsOnPage;
            ViewBag.Categories  = new BookCategoryDao().GetAll();

            if (Request.IsAjaxRequest())
            {
                return(PartialView(books));
            }

            return(View(books));
        }
Example #2
0
        // GET: Books
        public ActionResult Index(int?page, int?cat)
        {
            int itemsOnPage = 5;
            int pg          = page.HasValue ? page.Value : 1;
            int totalBooks;

            if (!cat.HasValue)
            {
                cat = null;
            }

            string pozdrav = "Lof lof";
            int    cislo   = 12;

            // Potřebuju uložit do kontaineru abych to dostal do view
            ViewBag.Pozdrav = pozdrav;
            ViewBag.Cislo   = cislo;
            ViewBag.Cat     = cat;

            BookDao bookDao = new BookDao();

            IList <Book> bPaged = bookDao.GetBooksPaged(itemsOnPage, pg, out totalBooks, cat);

            //IList<Book> booksPaged = bookDao.GetBooksInSection(cat);//bookDao.GetBooksPaged(itemsOnPage, pg, out totalBooks);
            List <Book> u = bPaged as List <Book>;

            bPaged = bPaged.OrderBy(x => x.Id).ToList();

            if (User.Identity.IsAuthenticated)
            {
                foreach (Book b in bPaged)
                {
                    if (CurrentUserRatedBook(b))
                    {
                        b.RateValue = -1;
                    }
                    else
                    {
                        b.RateValue = 1;
                    }
                }
            }

            KnihovnaUser user = new KnihovnaUserDao().GetByLogin(User.Identity.Name);

            ViewBag.Pages       = (int)Math.Ceiling((double)totalBooks / (double)itemsOnPage);
            ViewBag.CurrentPage = pg;
            ViewBag.PerPage     = itemsOnPage;
            ViewBag.total       = totalBooks;

            if (Request.IsAjaxRequest())
            {
                return(PartialView(u));
            }

            return(View(u)); // Passnu třídu
        }