public static Order CreateNewOrder(WebAssessmentContext db) { Order newOrder = new Order(); newOrder.CreatedDate = DateTime.Now; newOrder.OrderDate = DateTime.Now; db.Orders.Add(newOrder); db.SaveChanges(); return(newOrder); }
public static BasketItem addBasketItem(WebAssessmentContext db, int OrderId, Product product, int quantity = 1) { BasketItem basketItem = new BasketItem { OrderId = OrderId, CreatedDate = DateTime.Now, Price = product.Price, ProductId = product.Id, Quantity = quantity }; db.BasketItems.Add(basketItem); db.SaveChanges(); return(basketItem); }
public static void UpdateOrder(WebAssessmentContext db, Order order) { decimal _fullPrice = order.FullPrice; foreach (BasketItem item in order.Basket) { _fullPrice = _fullPrice + item.Price; } Order orderToUpdate = db.Orders.Find(order.Id); orderToUpdate.FullPrice = _fullPrice; db.SaveChanges(); }