public async Task <IActionResult> AddCart(int?id, string actionName, string queryString) { if (id == null) { return(NotFound()); } Book book = await _db.Books.FindAsync(id); if (book == null) { return(NotFound()); } AppUser user = await _userManager.FindByNameAsync(User.Identity.Name); BookInCart bookInCart = _db.BookInCarts.FirstOrDefault(bc => bc.BookId == book.Id); if (bookInCart == null) { BookInCart newBook = new BookInCart { BookId = book.Id, AppUserId = user.Id, Count = 1 }; _db.BookInCarts.Add(newBook); } else { bookInCart.Count++; } await _db.SaveChangesAsync(); if (actionName.Contains("/kitab/")) { return(RedirectToRoute(new { controller = "kitab", action = book.Slug })); } else if (actionName.Contains("BestSellers")) { return(Redirect("/BestSellers/Index" + queryString)); } else { return(Redirect("/NewBooks/Index" + queryString)); } }
public async Task <IActionResult> DeleteBook(int?id) { if (id == null) { return(NotFound()); } BookInCart bookInCart = _db.BookInCarts.FirstOrDefault(bc => bc.BookId == id); _db.BookInCarts.Remove(bookInCart); await _db.SaveChangesAsync(); return(RedirectToRoute(new { controller = "Basket", action = "Index", username = User.Identity.Name })); }