Ejemplo n.º 1
0
        public ActionResult PlaceOrder(string id)
        {
            var userName = User.Identity.GetUserName();
            /* Find the details of the customer placing the order*/
            var customer = db.Customers.Where(x => x.Email == userName).FirstOrDefault();

            /* Place the order */
            order_Service.AddOrder(customer);
            /* Get the last placed order by the cus.tomer */
            var order = order_Service.GetOrders()
                        .FindAll(x => x.Email == customer.Email)
                        .OrderByDescending(x => x.date_created)
                        .FirstOrDefault();

            /* If the customer requests delivery, save order address */
            if (id == "deliver")
            {
                address_Service.AddShippingAddress(new Shipping_Address()
                {
                    Order_ID      = order.Order_ID,
                    street_number = Convert.ToInt16(Session["street_number"].ToString()),
                    street_name   = Session["street_name"].ToString(),
                    City          = Session["City"].ToString(),
                    State         = Session["State"].ToString(),
                    ZipCode       = Session["ZipCode"].ToString(),
                    Country       = Session["Country"].ToString(),

                    Building_Name  = "",
                    Floor          = "",
                    Contact_Number = "",
                    Comments       = "",
                    Address_Type   = ""
                });
            }
            /* Migrate cart items to map as order items */
            order_Service.AddOrderItems(order, cart_Service.GetCartItems());
            /* Empty the cart items */
            cart_Service.EmptyCart();
            /* Update Order Tracking Report */
            order_Service.AddOrderTrackingReport(new Order_Tracking()
            {
                order_ID  = order.Order_ID,
                date      = DateTime.Now,
                status    = "Awaiting Payment",
                Recipient = ""
            });


            //Redirect to payment
            return(RedirectToAction("Payment", new { id = order.Order_ID }));
        }