public ActionResult PriceBetween(string lower, string higher, int active)
        {
            ViewData["active"] = active;
            var procedure     = new Procedure.Procedure();
            var priceproducts = procedure.FindMoneyBetween(decimal.Parse(lower), decimal.Parse(higher));

            ViewData["priceproducts"] = priceproducts;

            var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (cookie == null)
            {
                ViewBag.IsAuthenticated = false;
                return(View());
            }

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

            ViewBag.IsAuthenticated = true;
            ViewBag.UserName        = ticket.UserData;
            var repository = new ShoppingCartRepository();
            var Data       = repository.FindByMemberID(ticket.UserData);

            ViewData["count"] = Data.Count().ToString();
            return(View());
        }
        public ActionResult NewProduct()
        {
            ViewBag.Title = "新商品";

            var productrepository = new ProductRepository();
            var newProducts       = productrepository.NewProduct();

            ViewData["newProducts"] = newProducts;
            var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (cookie == null)
            {
                ViewBag.IsAuthenticated = false;
                return(View());
            }

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

            ViewBag.IsAuthenticated = true;
            ViewBag.UserName        = ticket.UserData;
            var repository = new ShoppingCartRepository();
            var Data       = repository.FindByMemberID(ticket.UserData);

            ViewData["count"] = Data.Count().ToString();

            return(View());
        }
        public ActionResult PopualityIndex()
        {
            ViewBag.Title = "熱銷產品介面";
            var Popuality            = new ProductRepository();
            var FindPopualityProduct = Popuality.PopularityProduct();


            //new list
            List <string> productcolor = new List <string>();
            List <string> productsize  = new List <string>();

            ViewBag.FindPopualityProduct = FindPopualityProduct;
            // ViewData["FindPopualityProduct"] = FindPopualityProduct;

            var popualitylist = new List <PopualityProduct>();

            foreach (var item in FindPopualityProduct)
            {
                PopualityProduct popuality = new PopualityProduct()
                {
                    image         = item.image,
                    ProductID     = item.ProductID,
                    ProductName   = item.ProductName,
                    Color         = item.Color,
                    StockQuantity = item.StockQuantity,
                    Description   = item.Description,
                    UnitPrice     = item.UnitPrice,
                    CategoryName  = item.CategoryName
                };
                popualitylist.Add(popuality);
            }
            //ViewData.Add();
            ViewData["popualitylist"] = popualitylist;
            ViewData["count"]         = popualitylist.Count();
            ViewData["productcolor"]  = productcolor.Distinct();
            ViewData["productsize"]   = productsize.Distinct();

            var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (cookie == null)
            {
                ViewBag.IsAuthenticated = false;
                return(View());
            }

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

            ViewBag.IsAuthenticated = true;
            ViewBag.UserName        = ticket.UserData;
            var repository = new ShoppingCartRepository();
            var Data       = repository.FindByMemberID(ticket.UserData);

            ViewData["count"] = Data.Count().ToString();
            return(View());
        }
        public ActionResult ShoppingCart()
        {
            var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (cookie == null)
            {
                ViewBag.IsAuthenticated = false;
                return(View());
            }

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

            ViewBag.IsAuthenticated = true;
            ViewBag.UserName        = ticket.UserData;

            ShoppingCartRepository repository = new ShoppingCartRepository();
            var Data = repository.FindByMemberID(ticket.UserData);

            List <ShoppingCartInformation> shoppingCarts = new List <ShoppingCartInformation>();
            decimal TotalPrice = 0;

            foreach (var item in Data)
            {
                ProductRepository productRepository = new ProductRepository();
                var productInformation = productRepository.FindById(item.ProductID);

                ProductFormatRepository productFormatRepository = new ProductFormatRepository();
                var productFormatInformation = productFormatRepository.FindById(item.ProductFormatID);

                ShoppingCartInformation shoppingCart = new ShoppingCartInformation()
                {
                    ShoppingCartID  = item.ShoppingCartID,
                    ProductFormatID = item.ProductFormatID,
                    ProductName     = productInformation.ProductName,
                    UnitPrice       = productInformation.UnitPrice,
                    Color           = productFormatInformation.Color,
                    Image           = productFormatInformation.Image,
                    Size            = productFormatInformation.Size,
                    Quantity        = item.Quantity
                };
                TotalPrice += productInformation.UnitPrice * item.Quantity;
                shoppingCarts.Add(shoppingCart);
            }

            ViewBag.ShoppingCart = shoppingCarts;
            ViewBag.TotalPrice   = TotalPrice;

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

            if (cookie == null)
            {
                ViewBag.IsAuthenticated = false;
                ViewData["iconcount"]   = "0";
                return(PartialView());
            }

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

            ViewBag.IsAuthenticated = true;
            ViewBag.UserName        = ticket.UserData;
            var repository = new ShoppingCartRepository();
            var Data       = repository.FindByMemberID(ticket.UserData);

            ViewData["iconcount"] = Data.Count().ToString();
            return(PartialView());
        }
        public ActionResult ColorFilter(string Colors)
        {
            Procedure.Procedure procedure = new Procedure.Procedure();
            ViewData["color"] = procedure.ColorFilters(Colors);

            var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (cookie == null)
            {
                ViewBag.IsAuthenticated = false;
                return(View());
            }

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

            ViewBag.IsAuthenticated = true;
            ViewBag.UserName        = ticket.UserData;
            var repository = new ShoppingCartRepository();
            var Data       = repository.FindByMemberID(ticket.UserData);

            ViewData["count"] = Data.Count().ToString();
            return(View());
        }
        public JsonResult Order(string name, string phone, string address, string memberID, decimal totalPrice)
        {
            if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(phone) || string.IsNullOrWhiteSpace(address))
            {
                return(Json("填空區不可有空白"));
            }
            else
            {
                if (Regex.Match(name, @"[\u3000-\u9FA5\x20]{2,4}").Success)
                {
                    if (Regex.Match(phone, @"(\(?\d{3,4}\)?)?[\s-]?\d{7,8}[\s-]?\d{0,4}").Success)
                    {
                        ShoppingCartRepository  shoppingCartRepository  = new ShoppingCartRepository();
                        OrdersRepository        ordersRepository        = new OrdersRepository();
                        EmployeesRepository     employeesRepository     = new EmployeesRepository();
                        ProductFormatRepository productFormatRepository = new ProductFormatRepository();
                        OrderDetailsRepository  orderDetailsRepository  = new OrderDetailsRepository();
                        ProductRepository       productRepository       = new ProductRepository();
                        var employees    = employeesRepository.GetAll();
                        var randomNumber = new Random().Next(0, employees.Count());


                        Orders orders = new Orders()
                        {
                            EmployeeID  = employees.ElementAt(randomNumber).EmployeeID,
                            MemberID    = memberID,
                            ShipName    = name,
                            ShipAddress = address,
                            ShipPhone   = phone,
                            OrderDate   = DateTime.Now,
                            Status      = "未送貨",
                            TotalPrice  = totalPrice
                        };

                        ordersRepository.Create(orders);
                        Procedure.Procedure procedure = new Procedure.Procedure();
                        var orderTempID = procedure.FindOrderID(memberID);

                        var shoppingCart = shoppingCartRepository.FindByMemberID(memberID);
                        Stack <OrderDetails> orderData = new Stack <OrderDetails>();
                        orderData.Clear();
                        foreach (var item in shoppingCart)
                        {
                            if (productFormatRepository.FindById(item.ProductFormatID).StockQuantity - item.Quantity >= 0)
                            {
                                OrderDetails orderDetails = new OrderDetails()
                                {
                                    OrderID         = orderTempID.OrderID,
                                    ProductFormatID = item.ProductFormatID,
                                    Quantity        = item.Quantity,
                                    UnitPrice       = productRepository.FindById(item.ProductID).UnitPrice
                                };
                                orderData.Push(orderDetails);
                            }
                            else
                            {
                                var productFormatTemp = productFormatRepository.FindById(item.ProductFormatID);
                                var productTemp       = productRepository.FindById(productFormatTemp.ProductID);


                                return(Json("產品:" + productTemp.ProductName + Environment.NewLine +
                                            "顏色:" + productFormatTemp.Color + Environment.NewLine +
                                            "尺寸:" + productFormatTemp.Size + Environment.NewLine +
                                            "剩餘數量:" + productFormatTemp.StockQuantity + Environment.NewLine +
                                            "請重新下訂!"));
                            }
                        }

                        foreach (var orderItem in orderData)
                        {
                            orderDetailsRepository.Create(orderItem);
                        }

                        shoppingCartRepository.DeleteByMemberId(memberID);

                        return(Json("下訂成功"));
                    }
                    else
                    {
                        return(Json("電話格式有誤"));
                    }
                }
                else
                {
                    return(Json("姓名不符合格式"));
                }
            }
        }