Esempio 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");
        }
Esempio n. 2
0
 /// <summary>
 /// Create a new Customer object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 public static Customer CreateCustomer(global::System.Int32 id)
 {
     Customer customer = new Customer();
     customer.ID = id;
     return customer;
 }
Esempio n. 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Customers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCustomers(Customer customer)
 {
     base.AddObject("Customers", customer);
 }
Esempio n. 4
0
 public ActionResult Index()
 {
     List<CartItemDetail> cart = GetCartItemDetails();
     Customer customer = new Customer();
     ViewBag.Customer = customer;
     return View(cart);
 }