コード例 #1
0
        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());
        }
コード例 #2
0
        public int ColorFilterItemCount(string Colors)
        {
            Procedure.Procedure procedure = new Procedure.Procedure();
            var Color = procedure.ColorFilters(Colors);

            return(Color.Count());
        }
コード例 #3
0
        public ActionResult Modal(string productid)
        {
            Procedure.Procedure procedure = new Procedure.Procedure();
            var ProductFormat             = procedure.GetFormatByProductID(int.Parse(productid));

            ViewData["ProductFormat"] = ProductFormat;
            var imagegroup = ProductFormat.Select((x) => x.Image).Distinct();

            ViewData["ImageGroup"] = imagegroup;
            var productName = ProductFormat.Select((x) => x.ProductName).Distinct();

            ViewData["ProductName"] = productName;
            var Description = ProductFormat.Select((x) => x.Description).Distinct();

            ViewData["Description"] = Description;
            var UnitPrice = ProductFormat.Select((x) => x.UnitPrice).Distinct();

            ViewData["UnitPrice"] = UnitPrice;
            var Color = ProductFormat.Select((x) => x.Color).Distinct();

            ViewData["Color"] = Color;
            var Size = ProductFormat.Select((x) => x.Size).Distinct();

            ViewData["Size"]      = Size;
            ViewData["ProductID"] = productid;
            return(PartialView());
        }
コード例 #4
0
        public int ModaltoCart(string productid, string size, string color, string quantity)
        {
            var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];

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

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

            ViewBag.IsAuthenticated = true;
            ViewData["UserName"]    = ticket.UserData;

            Procedure.Procedure procedure = new Procedure.Procedure();

            var ProductFormat = procedure.GetFormatIDByProductIDCS(int.Parse(productid), size, color);

            foreach (var item in ProductFormat)
            {
                productformatid = item.ProductFormatID;
                stock           = item.StockQuantity;
                image           = item.Image;
                productName     = item.ProductName;
                unitPrice       = item.UnitPrice;
            }

            var repeat = procedure.SearchRepeatCart(ticket.UserData, productformatid);

            if (repeat != null)
            {
                var isempty = 4;
                return(isempty);
            }
            else
            {
                if (int.Parse(quantity) <= stock)
                {
                    ShoppingCart shoppingCart = new ShoppingCart
                    {
                        MemberID        = ticket.UserData,
                        ProductFormatID = productformatid,
                        ProductID       = int.Parse(productid),
                        Quantity        = int.Parse(quantity),
                    };
                    var repository = new ShoppingCartRepository();
                    repository.Create(shoppingCart);
                    var isempty = 2;
                    CartIconNumber();
                    return(isempty);
                }
                else
                {
                    var isempty = 3;
                    return(isempty);
                }
            }
        }
コード例 #5
0
        public ActionResult Quantity(string color, string size, string productid)
        {
            int quantitynumber = 0;

            Procedure.Procedure procedure = new Procedure.Procedure();
            var ProductFormat             = procedure.GetFormatIDByProductIDCS(int.Parse(productid), size, color);

            foreach (var item in ProductFormat)
            {
                quantitynumber = item.StockQuantity;
            }
            ;
            if (ProductFormat == null)
            {
                ViewData["quantity"] = "0";
            }
            else
            {
                ViewData["quantity"] = quantitynumber.ToString();
            }
            return(PartialView());
        }
コード例 #6
0
        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());
        }
コード例 #7
0
        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("姓名不符合格式"));
                }
            }
        }