Exemplo n.º 1
0
        public RedirectToRouteResult Checkout(string firstName, string lastName, string emailAddress)
        {
            List<CartItemDetail> cart = GetCartItemDetails();

            decimal? totalAmount = (from c in cart
                                   select c.UnitPrice * c.Quantity).Sum();
            Customer customer = new Customer
            {
                FirstName = firstName,
                LastName = lastName,
                EmailAddress = emailAddress,
                JoinDate = DateTime.Now
            };

            _db.Customers.AddObject(customer);
            int customerID = _db.SaveChanges();

            Order order = new Order
            {
                CustomerID = customerID,
                OrderDate = DateTime.Now,
                Status = "New",
                TotalAmount = (decimal)totalAmount
            };

            _db.Orders.AddObject(order);
            int orderID = _db.SaveChanges();

            List<OrderItem> orderItems = (from c in cart
                                         select new OrderItem
                                         {
                                             OrderID = orderID,
                                             ProductID = c.ProductID,
                                             Quantity = c.Quantity,
                                             UnitPrice = (decimal)c.UnitPrice,
                                             TotalAmount = c.Quantity * (decimal)c.UnitPrice
                                         }).ToList();
            foreach (OrderItem item in orderItems)
            {
                _db.OrderItems.AddObject(item);
                _db.SaveChanges();
            }
            System.Web.HttpContext.Current.Session["cartItmes"] = null;
            return RedirectToAction("Index", "Order");
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create a new Order object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="customerID">Initial value of the CustomerID property.</param>
 /// <param name="totalAmount">Initial value of the TotalAmount property.</param>
 /// <param name="orderDate">Initial value of the OrderDate property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 public static Order CreateOrder(global::System.Int32 id, global::System.Int32 customerID, global::System.Decimal totalAmount, global::System.DateTime orderDate, global::System.String status)
 {
     Order order = new Order();
     order.ID = id;
     order.CustomerID = customerID;
     order.TotalAmount = totalAmount;
     order.OrderDate = orderDate;
     order.Status = status;
     return order;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Orders EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOrders(Order order)
 {
     base.AddObject("Orders", order);
 }