示例#1
0
        public OrderStatus ChangeOrderStatus(Order order)
        {
            Order orderToModify = db.Orders.Find(order.OrderId);

            orderToModify.OrderStatus = order.OrderStatus;
            db.SaveChanges();

            return(order.OrderStatus);
        }
示例#2
0
        public Order CreateNewOrder(Order newOrder, string userId)
        {
            var cart = GetCart();

            newOrder.DateAdded = DateTime.Now;
            newOrder.UserId    = userId;
            db.Orders.Add(newOrder);

            if (newOrder.OrderItems == null)
            {
                newOrder.OrderItems = new List <OrderItem>();
            }

            decimal cartPrice = 0;

            foreach (var cartItem in cart)
            {
                var newOrderItem = new OrderItem()
                {
                    BookId   = cartItem.Book.BookId,
                    Quantity = cartItem.Quantity,
                    Price    = cartItem.Book.Price
                };
                cartPrice += (cartItem.Quantity * cartItem.Book.Price);
                newOrder.OrderItems.Add(newOrderItem);
            }
            newOrder.Price = cartPrice;
            db.SaveChanges();

            return(newOrder);
        }