示例#1
0
 public IActionResult OnGet()
 {
     BookCatsInfo = SessionExtensions.GetCounts(HttpContext.Session).ToString();
     Books        = OrderBookList();
     if (Books != null)
     {
         return(Page());
     }
     return(Redirect("/"));
 }
示例#2
0
        public async Task <IActionResult> OnGetAsync(int?id, int?addCatId)
        {
            BookCatsInfo = SessionExtensions.GetCounts(HttpContext.Session).ToString();
            if (id == null)
            {
                return(NotFound());
            }
            if (addCatId != null)
            {
                string key = addCatId.Value.ToString();
                BookCats = SessionExtensions.Get <IDictionary <string, int> >(HttpContext.Session, "bookCats");
                if (BookCats == null)
                {
                    BookCats = new Dictionary <string, int>();
                }
                if (BookCats.ContainsKey(key))
                {
                    BookCats[key]++;
                }
                else
                {
                    BookCats.Add(key, 1);
                }

                SessionExtensions.Set <IDictionary <string, int> >(HttpContext.Session, "bookCats", BookCats);
                return(Redirect("/Details?id=" + id));
            }
            Book = await _context
                   .Book
                   .Include(b => b.Author)
                   .Include(b => b.Category)
                   .FirstOrDefaultAsync(m => m.ID == id);

            if (Book == null)
            {
                return(NotFound());
            }
            return(Page());
        }
示例#3
0
        public async Task <ActionResult> OnGetAsync(int?id, int?clearData)
        {
            if (clearData != null && clearData.Value == 1)
            {
                HttpContext.Session.Remove("bookCats");
            }
            if (id != null)
            {
                string key = id.Value.ToString();
                BookCats = SessionExtensions.Get <IDictionary <string, int> >(HttpContext.Session, "bookCats");
                if (BookCats == null)
                {
                    BookCats = new Dictionary <string, int>();
                }
                if (BookCats.ContainsKey(key))
                {
                    BookCats[key]++;
                }
                else
                {
                    BookCats.Add(key, 1);
                }

                SessionExtensions.Set <IDictionary <string, int> >(HttpContext.Session, "bookCats", BookCats);
                return(Redirect("/"));
            }
            BookCatsInfo = SessionExtensions.GetCounts(HttpContext.Session).ToString();

            var books = from b in _context.Book
                        join c in _context.Category on b.CategoryID equals c.ID
                        join a in _context.Author on b.AuthorID equals a.ID
                        select b;

            if (!string.IsNullOrEmpty(SearchString))
            {
                books = books.Where(b => b.Title.Contains(SearchString));
            }
            if (!string.IsNullOrEmpty(BookAuthor))
            {
                Int64 tempid = Convert.ToInt64(BookAuthor);
                books = books.Where(b => b.AuthorID == tempid);
            }
            if (!string.IsNullOrEmpty(BookCategory))
            {
                Int64 tempid = Convert.ToInt64(BookCategory);
                books = books.Where(b => b.CategoryID == tempid);
            }
            var authorsQuery = from a in _context.Author
                               orderby a.Name
                               select a;

            Authors = new SelectList(authorsQuery.AsNoTracking(),
                                     "ID", "Name");
            var categoriesQuery = from c in _context.Category
                                  orderby c.Title
                                  select c;

            Categories = new SelectList(categoriesQuery.AsNoTracking(),
                                        "ID", "Title");
            Book = await books
                   .Include(b => b.Author)
                   .Include(b => b.Category)
                   .AsNoTracking()
                   .ToListAsync();

            return(Page());
        }
示例#4
0
 public void OnGet()
 {
     BookCatsInfo = SessionExtensions.GetCounts(HttpContext.Session).ToString();
 }