public async Task <object> Update([FromBody] Book book) { _context.Add(book); await _context.SaveChangesAsync(); return(BookViewModel.Create(book)); }
// GET: Book public ActionResult Index(int?pageNumber, string sortOrder) { int pageSize = 2; ViewData["CurrentSort"] = sortOrder; ViewData["BookSortParm"] = String.IsNullOrEmpty(sortOrder) ? "book_desc" : ""; ViewData["AuthorSortParm"] = sortOrder == "Author" ? "author_desc" : "Author"; var books = bookService.GetAll().AsQueryable(); switch (sortOrder) { case "book_desc": books = books.OrderByDescending(b => b.Title); break; case "Author": books = books.OrderBy(b => b.AuthorList); break; case "author_desc": books = books.OrderByDescending(b => b.AuthorList); break; default: books = books.OrderBy(b => b.Title); break; } var bookViewModel = BookViewModel.Create(books.ToList(), pageNumber ?? 1, pageSize); return(View(bookViewModel)); }
public IActionResult Create() { var bookViewModel = new BookViewModel(); bookViewModel.Create(2); return(View(bookViewModel)); }
public async Task <IActionResult> Create([FromBody] BookFormModel bookForm) { var book = new Book { Id = bookForm.Id, Title = bookForm.Title, Description = bookForm.Description, DifficultyId = bookForm.Difficulty, Categories = bookForm.Categories .Select(guid => _context.Categories.Find(guid)) .ToList() }; await _context.AddAsync(book); await _context.SaveChangesAsync(); return(Ok(BookViewModel.Create(book))); }