public bool AddProductToActiveOrder(string productId, string userId) { var product = context.Products.Find(productId); var order = context.Orders.SingleOrDefault(o => o.CashierId == userId && o.Status == OrderStatus.Active); if (product == null || order == null) { return(false); } var orderProduct = new OrderProduct() { OrderId = order.Id, ProductId = product.Id }; order.Products.Add(orderProduct); context.OrdersProducts.Add(orderProduct); context.Update(order); context.SaveChanges(); return(true); }