예제 #1
0
        public ActionResult payment()
        {
            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 product_service  = new ProductsService();

            var user   = customer_service.FindByCustomerAccount(ticket.Name);
            var items  = shopping_service.FindByCustomer(user.CustomerID);
            var result = new List <decimal>();

            foreach (var item in items)
            {
                result.Add(product_service.FindByID(item.ProductID).UnitPrice *item.Quantity);
            }

            ViewBag.Total = result.Sum();

            return(View());
        }
        public ActionResult CountCart()
        {
            var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (cookie == null)
            {
                ViewBag.Count = 0;
            }
            else
            {
                var ticket = FormsAuthentication.Decrypt(cookie.Value);

                if (ticket == null)
                {
                    ViewBag.Count = 0;
                    return(PartialView());
                }

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

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

                var count = shopping_service.FindByCustomer(user.CustomerID).Count();

                ViewBag.Count = count;
            }

            return(PartialView());
        }
예제 #3
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"));
            }
        }
예제 #4
0
        // GET: ShoppingCart
        public ActionResult detail()
        {
            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 product_service  = new ProductsService();
            var photo_service    = new ProductPhotoService();

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

            var items = shopping_service.FindByCustomer(user.CustomerID);

            var result = new List <ShppingCartModel>();

            foreach (var item in items)
            {
                ShppingCartModel model = new ShppingCartModel();

                model.Image       = photo_service.FindById(item.ProductID).First().PhotoPath;
                model.ProductID   = item.ProductID;
                model.ProductName = product_service.FindByID(item.ProductID).ProductName;
                model.Color       = product_service.FindByID(item.ProductID).Color;
                model.Size        = product_service.FindByID(item.ProductID).Size;
                model.Amount      = item.Quantity;
                model.UnitPrice   = product_service.FindByID(item.ProductID).UnitPrice;
                model.Total       = product_service.FindByID(item.ProductID).UnitPrice *item.Quantity;

                result.Add(model);
            }

            ViewData.Add("list", result);

            return(View());
        }
예제 #5
0
        public ActionResult Index(ProductList ProductList)
        {
            var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (cookie == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            ProductsService            productservice             = new ProductsService();
            CustomerService            customerservice            = new CustomerService();
            ShoppingcartDetailsService ShoppingcartDetailsService = new ShoppingcartDetailsService();
            var ticket  = FormsAuthentication.Decrypt(cookie.Value);
            var user    = customerservice.FindByCustomerAccount(ticket.Name);
            var product = productservice.FindIdByName(ProductList.ProductName, ProductList.Size, ProductList.Color);

            //var stock = productservice.CheckStock(product.ProductID, ProductList.Num);
            if (product.Downtime != null || product.UnitsInStock == 0)
            {
                TempData.Add("NoItem", true);
                return(RedirectToAction("Product"));
            }

            if (ShoppingcartDetailsService.FindByCustomer(user.CustomerID).Any((x) => x.ProductID == product.ProductID))
            {
                TempData.Add("HasItem", true);
                return(RedirectToAction("Product"));
            }

            ShoppingcartDetailsService.Create(new ShoppingcartDetails()
            {
                CustomerID = user.CustomerID,
                ProductID  = product.ProductID,
                Quantity   = ProductList.Num
            });

            TempData.Add("HasItem", false);
            return(RedirectToAction("Product"));
        }
예제 #6
0
        public ActionResult UpdateShoppingcart(int ProductID, int Quantity)
        {
            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);

            shopping_service.Update(new ShoppingcartDetails()
            {
                ProductID = ProductID, CustomerID = user.CustomerID, Quantity = Quantity
            });

            return(RedirectToAction("detail"));
        }
예제 #7
0
        public ActionResult DeleteOne_detail(int ProductID)
        {
            var receiveID = ProductID;

            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);

            shopping_service.DeleteOneForUser(new ShoppingcartDetails {
                CustomerID = user.CustomerID, ProductID = receiveID, Quantity = 0
            });

            return(RedirectToAction("detail"));
        }