コード例 #1
0
        public ActionResult CreateOrder(Orderinfo order)
        {
            var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (cookie == null)
            {
                return(RedirectToAction("Login", "Login"));
            }

            var ticket = FormsAuthentication.Decrypt(cookie.Value);

            var customer_service = new CustomerService();
            var shopping_service = new ShoppingcartDetailsService();

            var user = customer_service.FindByCustomerAccount(ticket.Name);

            var neworder = new Order();

            neworder.Address         = order.Address;
            neworder.Payment         = order.Payment;
            neworder.Transport       = order.Transport;
            neworder.OrderDay        = DateTime.Now;
            neworder.StatusUpdateDay = DateTime.Now;
            neworder.Status          = "處理中";
            neworder.CustomerID      = user.CustomerID;

            var ShoppingcartList = shopping_service.FindByCustomer(user.CustomerID).ToList();

            if (ShoppingcartList.Count == 0)
            {
                return(RedirectToAction("detail"));
            }

            var status = shopping_service.ConfirmOrders(ShoppingcartList, neworder);

            if (status == "OrderSuccess")
            {
                return(RedirectToAction("order"));
            }
            else
            {
                return(RedirectToAction("detail"));
            }
        }
コード例 #2
0
        public void ConfirmOrdersTest()
        {
            List <ShoppingcartDetails> shoppingcar = new List <ShoppingcartDetails>();

            shoppingcar.Add(new ShoppingcartDetails()
            {
                CustomerID = 3, ProductID = 2, Quantity = 1
            });
            shoppingcar.Add(new ShoppingcartDetails()
            {
                CustomerID = 3, ProductID = 4, Quantity = 1
            });
            Order order = new Order
            {
                CustomerID = 3,
                Transport  = "宅配",
                Payment    = "信用卡",
                Status     = "處理中",
                Address    = "香山街23號"
            };
            var result = service.ConfirmOrders(shoppingcar, order);

            Assert.IsTrue(result == "OrderSuccess");
        }