Example #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 }));
        }
        private void SubmitOrder()
        {
            try
            {
                // Add the order
                order_service.AddOrder(table, employee, orderedItemsList);
                // Reset inpute values
                ResetInputValues();
                // Remove active states
                RemoveActiveMenuCardState();
                // Clear order list
                ClearOrderList();
                // Reset currentMenuItem
                currentMenuItem = null;

                MessageBox.Show(
                    "Order is succefully placed", // Exception Message
                    "Order succefull",            // Message box caption (title)
                    MessageBoxButtons.OK,         // Close button that return an exit code of '0'.
                    MessageBoxIcon.Information    // Message box theme.
                    );

                Overview overview = new Overview(employee);
                overview.Show();

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    ex.Message,                    // Exception Message
                    "Adding order process error.", // Message box caption (title)
                    MessageBoxButtons.OK,          // Close button that return an exit code of '0'.
                    MessageBoxIcon.Error           // Message box theme.
                    );
            }
        }