public IActionResult RemoveProduct(int id) { Products product = _context.Productss.Where(x => x.ProductID == id).FirstOrDefault(); _context.Remove(product); _context.SaveChanges(); return(View("Index")); }
public IActionResult DeleteUser(int id) { Users user = _context.Userss.Where(x => x.UserId == id).FirstOrDefault(); _context.Remove(user); _context.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// Removing the cart item /// </summary> /// <param name="customerId"></param> /// <param name="menuId"></param> /// <returns></returns> public bool RemoveCartItems(int customerId, int restaurantId, int menuId) { try { if (!DoesCartMasterExists(customerId)) { throw new Exception("No items are there in your cart. Continue shopping"); } int tblCartMasterId = (from cartMaster in _orderManagementContext.TblCartMaster where cartMaster.TblCustomerId == customerId && cartMaster.TblRestaurantId == restaurantId && cartMaster.IsActive select cartMaster.Id).FirstOrDefault(); if (tblCartMasterId == 0) { throw new Exception($"Cannot remove menu for restaurant {restaurantId}! Cart contains items from different restaurant"); } if (!DoesCartItemsExists(tblCartMasterId)) { throw new Exception("Error in fetching cart items"); } TblCartItems tblCartItem = (from cartItems in _orderManagementContext.TblCartItems where cartItems.TblCartMasterId == tblCartMasterId && cartItems.TblMenuId == menuId select cartItems).FirstOrDefault(); if (tblCartItem != null) { throw new Exception($"Menu with id {menuId} not found for the customer id {customerId}"); } _orderManagementContext.Remove(tblCartItem); return(SaveChanges()); } catch (Exception ex) { throw new Exception(ex.Message); } }
public Order DeleteOrderById(int id) { try { var order = _ctx.Orders .Include(o => o.Client) .FirstOrDefault(o => o.Id == id); _ctx.Remove(order); return(order); } catch (Exception ex) { _logger.LogError($"Failed to delete order by id: {ex}"); return(null); } }
public Client DeleteClientById(int id) { try { var client = _ctx.Clients .Where(c => c.Id == id) .FirstOrDefault(); _ctx.Remove(client); return(client); } catch (Exception ex) { _logger.LogError($"Failed to delete client by id: {ex}"); return(null); } }
public virtual void Delete(T entity) { _context.Remove(entity); }