public IActionResult RemoveFromList(int id) { if (HttpContext.Session.GetString("CurrentUserFirstName") == null) { return(RedirectToAction("Index", "Home")); } ShoppingListsProducts product = _context.ShoppingListsProducts.SingleOrDefault(slp => slp.id == id); int listId = product.ShoppingListId; _context.ShoppingListsProducts.Remove(product); _context.SaveChanges(); return(RedirectToAction("ListDetails", new { id = listId })); }
public IActionResult AddToList(int productId, int repeat, int listId) { if (HttpContext.Session.GetString("CurrentUserFirstName") == null) { return(RedirectToAction("Index", "Home")); } if (productId > 0) { ShoppingListsProducts toAdd = new ShoppingListsProducts { ShoppingListId = listId, ProductId = productId, Repeat = repeat, }; _context.ShoppingListsProducts.Add(toAdd); _context.SaveChanges(); } return(RedirectToAction("ListDetails", new { id = listId })); }