示例#1
0
        public virtual ActionResult AddCompanyToCart(int company_Id, string name)
        {
            var listProductCompany = _productService.GetAllProductInCompanyForAddToCart_(company_Id);

            if (Request.Cookies["Basket"] != null)
            {
                HttpCookie cookie      = Request.Cookies["Basket"];
                string     valueCookie = cookie["Cart"];

                //Deseralize && Decrypt
                var resultDecrypt = new EnDecryption().Decryption(valueCookie);
                var list          = SerializeList.DeseraLizeList(resultDecrypt);

                list.AddRange(listProductCompany);

                //Seralize && Encrypt
                var resultSeralize = SerializeList.SeralizeList(list);
                var resultEncrypt  = new EnDecryption().Encryption(resultSeralize);
                cookie.Values["Cart"] = resultEncrypt;
                cookie.Expires        = DateTime.Now.AddMinutes(15);
                Response.Cookies.Add(cookie);
                return(Json(new { result = "true", value = "محصول مورد نظر با موفقیت به سبد خرید اضافه شد" }));
            }
            else
            {
                var        resultSeralize = SerializeList.SeralizeList(listProductCompany);
                var        resultEncrypt  = new EnDecryption().Encryption(resultSeralize);
                HttpCookie cookie         = new HttpCookie("Basket");
                cookie.Values["Cart"] = resultEncrypt;
                cookie.Expires        = DateTime.Now.AddMinutes(15);
                Response.Cookies.Add(cookie);
                return(Json(new { result = "true", value = "محصول مورد نظر با موفقیت به سبد خرید اضافه شد" }));
            }
        }
示例#2
0
        public virtual ActionResult RemoveItem(int product_Id)
        {
            var        newList     = new List <BasketViewModel>();
            HttpCookie cookie      = Request.Cookies["Basket"];
            string     valueCookie = cookie["Cart"];

            //Deseralize && Decrypt
            var resultDecrypt = new EnDecryption().Decryption(valueCookie);
            var list          = SerializeList.DeseraLizeList(resultDecrypt);

            if (list.FindIndex(x => x.Product_Id == product_Id) != -1)
            {
                list.Remove(list.Find(x => x.Product_Id == product_Id));
                var resultSerialize  = SerializeList.SeralizeList(list);
                var resultEncryption = new EnDecryption().Encryption(resultSerialize);
                cookie.Values["Cart"] = resultEncryption;
                Response.Cookies.Add(cookie);
                return(Json(new { result = "true" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { result = "false" }, JsonRequestBehavior.AllowGet));
            }
        }
示例#3
0
        public virtual ActionResult Index(List <BasketViewModel> model)
        {
            if (Request.Cookies["Basket"] != null)
            {
                var        newList     = new List <BasketViewModel>();
                HttpCookie cookie      = Request.Cookies["Basket"];
                string     valueCookie = cookie["Cart"];

                //Deseralize && Decrypt
                var resultDecrypt = new EnDecryption().Decryption(valueCookie);
                var previouslist  = SerializeList.DeseraLizeList(resultDecrypt);

                foreach (var item in model)
                {
                    if (previouslist.FindIndex(x => x.Product_Id == item.Product_Id) == -1)
                    {
                        continue;
                    }
                    var successModel = previouslist.Find(x => x.Product_Id == item.Product_Id);
                    successModel.Quantity = item.Quantity;
                    newList.Add(successModel);
                }

                var resultSeralize   = SerializeList.SeralizeList(newList);
                var resultEncryption = new EnDecryption().Encryption(resultSeralize);

                cookie.Values["Cart"] = resultEncryption;
                Response.Cookies.Set(cookie);

                return(RedirectToAction(MVC.Cart.ActionNames.Information));
            }
            else
            {
                return(RedirectToAction(MVC.Home.ActionNames.Index, MVC.Home.Name));
            }
        }
示例#4
0
        public virtual ActionResult Add(int product_Id, string name, double price)
        {
            var modelDb = _productService.GetByIdExamAddToCart(product_Id);

            if (modelDb.Id == product_Id && modelDb.Price == price)
            {
                if (_productService.CheckExistProductForAddToCart_(product_Id, price))
                {
                    if (Request.Browser.Cookies)
                    {
                        try
                        {
                            if (Request.Cookies["Basket"] != null)
                            {
                                HttpCookie cookie      = Request.Cookies["Basket"];
                                string     valueCookie = cookie["Cart"];

                                //Deseralize && Decrypt
                                var resultDecrypt = new EnDecryption().Decryption(valueCookie);
                                var list          = SerializeList.DeseraLizeList(resultDecrypt);


                                if (list.FindIndex(x => x.Product_Id == product_Id) != -1)
                                {
                                    return(Json(new { result = "true", value = "این محصول قبلا به سبد خرید شما اضافه شده است", Status = "duplicate" }, JsonRequestBehavior.AllowGet));
                                }

                                list.Add(new BasketViewModel {
                                    Name = name, Price = price, Product_Id = product_Id, Quantity = 1, StatusTypeOrder = StatusTypeOrder.EWPR, PrimaryImage = modelDb.PrimaryImage
                                });

                                var count = list.Count();

                                //Seralize && Encrypt
                                var resultSeralize = SerializeList.SeralizeList(list);
                                var resultEncrypt  = new EnDecryption().Encryption(resultSeralize);
                                cookie.Values["Cart"] = resultEncrypt;
                                cookie.Expires        = DateTime.Now.AddYears(1);
                                Response.Cookies.Set(cookie);
                                return(Json(new { result = "true", value = "محصول مورد نظر با موفقیت به سبد خرید اضافه شد", Status = "Success" }, JsonRequestBehavior.AllowGet));
                            }
                            else
                            {
                                var list = new List <BasketViewModel>()
                                {
                                    new BasketViewModel {
                                        Name = name, Price = price, Product_Id = product_Id, Quantity = 1, StatusTypeOrder = StatusTypeOrder.EWPR, PrimaryImage = modelDb.PrimaryImage
                                    }
                                };
                                var        resultSeralize = SerializeList.SeralizeList(list);
                                var        resultEncrypt  = new EnDecryption().Encryption(resultSeralize);
                                HttpCookie cookie         = new HttpCookie("Basket");
                                cookie.HttpOnly       = true;
                                cookie.Values["Cart"] = resultEncrypt;
                                cookie.Expires        = DateTime.Now.AddYears(1);
                                Response.Cookies.Add(cookie);
                                return(Json(new { result = "true", value = "محصول مورد نظر با موفقیت به سبد خرید اضافه شد", Status = "Success" }, JsonRequestBehavior.AllowGet));
                            }
                        }
                        catch
                        {
                            return(Json(new { result = "false", value = "متاسفانه در زمان اضافه کردن محصول به سبد خرید خطایی ایجاد شده است / صفحه را دوباره تازه سازی نمایید", Status = "Fail" }, JsonRequestBehavior.AllowGet));
                        }
                    }
                    else
                    {
                        return(Json(new { result = "false", value = "خواهشمندیم کوکی مرورگر خود را فعال نمایید", Status = "Fail" }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    return(Json(new { result = "false", value = "متاسفانه در زمان اضافه کردن محصول به سبد خرید خطایی ایجاد شده است / صفحه را دوباره تازه سازی نمایید", Status = "Fail" }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { result = "false", value = "متاسفانه در زمان اضافه کردن محصول به سبد خرید خطایی ایجاد شده است / صفحه را دوباره تازه سازی نمایید", Status = "Fail" }, JsonRequestBehavior.AllowGet));
            }
        }