Ejemplo n.º 1
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                if (id == null)
                {
                    return(NotFound());
                }
                Book = await _context.Book.FirstOrDefaultAsync(m => m.ID == id);

                if (Book == null)
                {
                    return(NotFound());
                }
                ViewData["PublisherID"] = new SelectList(_context.Set <Publisher>(), "ID", "PublisherName");
                return(NotFound());
            }

            Book = await _context.Book
                   .Include(b => b.Publisher)
                   .Include(b => b.BookCategories).ThenInclude(b => b.Category)
                   .AsNoTracking()
                   .FirstOrDefaultAsync(m => m.ID == id);

            if (Book == null)
            {
                return(NotFound());
            }
            PopulateAssignedCategoryData(_context, Book);
            ViewData["PublisherID"] = new SelectList(_context.Publisher, "ID", "PublisherName");
            return(Page());
        }
Ejemplo n.º 2
0
        public IActionResult OnGet()
        {
            var book = new Book();

            book.BookCategories = new List <BookCategory>();
            PopulateAssignedCategoryData(_context, book);

            ViewData["PublisherID"] = new SelectList(_context.Set <Publisher>(), "ID", "PublisherName");
            return(Page());
        }