public async Task <IActionResult> Edit(int?shopId, int?bookId, [Bind("ShopId,BookId,StockLevel")] ShopBook shopBook) { if (shopBook.ShopId != shopId || shopBook.BookId != bookId) { return(NotFound()); } if (ModelState.IsValid) { try { await _shopService.UpdateBookInShop(shopBook); } catch (DbUpdateConcurrencyException) { if (shopBook == null) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ShopId"] = new SelectList(await _shopService.GetAllShops(), "Id", "Name", shopBook.ShopId); ViewData["BookId"] = new SelectList(await _dataService.GetAllBooks(), "Id", "Title", shopBook.BookId); return(View(shopBook)); }
public async Task <IActionResult> Create([Bind("ShopId,BookId,StockLevel")] ShopBook shopBook) { if (ModelState.IsValid) { await _shopService.AddBookToShop(shopBook); return(RedirectToAction(nameof(Index))); } ViewData["ShopId"] = new SelectList(await _shopService.GetAllShops(), "Id", "Name", shopBook.ShopId); ViewData["BookId"] = new SelectList(await _dataService.GetAllBooks(), "Id", "Title", shopBook.BookId); return(View(shopBook)); }
public async Task <bool> UpdateBookInShop(ShopBook shopBook) { return(await _unitOfWork.ShopBook.UpdateAndSave(shopBook)); }
public async Task <bool> AddBookToShop(ShopBook shopBook) { _unitOfWork.ShopBook.Add(shopBook); return(await _unitOfWork.Save()); }