示例#1
0
        public ActionResult CheckoutWithNewCustomer(FormCollection form)
        {
            try
            {
                // Check autherization
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    Session["Cart"] = null;
                    return RedirectToAction("Index", "Home");
                }

                List<CartViewModel> inputCartList = Session["Cart"] as List<CartViewModel>;

                string customerNameString = form["customerName"];
                string customerEmailString = form["customerEmail"];
                string customerAddressString = form["customerAddress"];
                string customerPhoneNumberString = form["customerPhoneNumber"];
                string customerTaxCodeString = form["customerTaxCode"];
                string usernameString = form["username"];
                if (
                    !(customerNameString.IsEmpty() || customerAddressString.IsEmpty() || customerPhoneNumberString.IsEmpty() ||
                      customerTaxCodeString.IsEmpty() || customerEmailString.IsEmpty() || usernameString.IsEmpty()))
                {
                    CustomerViewModel customer = new CustomerViewModel();
                    customer.CustomerName = customerNameString;
                    customer.CustomerAddress = customerAddressString;
                    customer.CustomerPhoneNumber = customerPhoneNumberString;
                    customer.CustomerTaxCode = customerTaxCodeString;
                    customer.Username = usernameString;
                    customer.CustomerEmail = customerEmailString;
                    Session["CustomerId"] = 0;
                    Session["NewCustomer"] = customer;
                    OrderBusiness orderBusiness = new OrderBusiness();
                    OrderViewModel order = orderBusiness.MakeOrderViewModel(inputCartList, null, customer);
                    ViewBag.TreeView = "order";
                    ViewBag.TreeViewMenu = "addOrder";
                    return View("CheckoutWithCustomer", order);
                }
                return RedirectToAction("AddCustomerToOrder");
            }
            catch (Exception)
            {
                return RedirectToAction("ManageError", "Error");
            }
        }
示例#2
0
        public ActionResult CheckoutWithCustomer(int customerId)
        {
            try
            {
                // Check autherization
                User staffUser = Session["User"] as User;
                if (staffUser == null || Session["UserRole"] == null || (int)Session["UserRole"] != 2)
                {
                    Session["Cart"] = null;
                    return RedirectToAction("Index", "Home");
                }

                List<CartViewModel> inputCartList = Session["Cart"] as List<CartViewModel>;
                OrderBusiness orderBusiness = new OrderBusiness();
                OrderViewModel order = orderBusiness.MakeOrderViewModel(inputCartList, customerId, null);
                if (!order.IsEnoughMaterial)
                {
                    ViewBag.ShortageOfMaterial = true;
                }
                ViewBag.TaxRate = orderBusiness.GetVatRateAtTime(DateTime.Now);
                Session["CustomerId"] = customerId;
                ViewBag.TreeView = "order";
                ViewBag.TreeViewMenu = "addOrder";
                return View(order);
            }
            catch (Exception)
            {
                return RedirectToAction("ManageError", "Error");
            }
        }