Exemple #1
0
        public async virtual Task <ActionResult> Confirmation()
        {
            var list = new List <BasketViewModel>();

            if (Request.Browser.Cookies)
            {
                if (Request.Cookies["Basket"] != null)
                {
                    HttpCookie cookie        = Request.Cookies["Basket"];
                    string     valueCookie   = cookie["Cart"];
                    var        resultDecrypt = new EnDecryption().Decryption(valueCookie);
                    list = SerializeList.DeseraLizeList(resultDecrypt);
                    var _user = await _userManager.FindUserByIdForShow_(User.Identity.GetUserId <int>());

                    ViewBag.user = _user;
                    return(View(list));
                }
                else
                {
                    return(RedirectToAction(MVC.Home.ActionNames.Index, MVC.Home.Name));
                }
            }
            else
            {
                return(RedirectToAction("/"));
            }
        }
Exemple #2
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 = "محصول مورد نظر با موفقیت به سبد خرید اضافه شد" }));
            }
        }
Exemple #3
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));
            }
        }
Exemple #4
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));
            }
        }
Exemple #5
0
        public virtual ActionResult Index()
        {
            var list = new List <BasketViewModel>();

            if (Request.Browser.Cookies)
            {
                if (Request.Cookies["Basket"] != null)
                {
                    HttpCookie cookie        = Request.Cookies["Basket"];
                    string     valueCookie   = cookie["Cart"];
                    var        resultDecrypt = new EnDecryption().Decryption(valueCookie);
                    list = SerializeList.DeseraLizeList(resultDecrypt);
                    return(View(list));
                }
                else
                {
                    return(View(list));
                }
            }
            else
            {
                return(RedirectToAction("/"));
            }
        }
Exemple #6
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));
            }
        }
Exemple #7
0
        public virtual ActionResult Payment(StatusTypePay selectPayment = StatusTypePay.Online)
        {
            var list = new List <BasketViewModel>();

            if (Request.Browser.Cookies)
            {
                if (Request.Cookies["Basket"] != null)
                {
                    HttpCookie cookie        = Request.Cookies["Basket"];
                    string     valueCookie   = cookie["Cart"];
                    var        resultDecrypt = new EnDecryption().Decryption(valueCookie);
                    list = SerializeList.DeseraLizeList(resultDecrypt);
                    var sale = new Sale
                    {
                        Date           = DateTime.Now,
                        Postage        = 8000,
                        Price          = list.Sum(x => x.Price),
                        StatusTypePay  = selectPayment.ToString(),
                        StatusUltimate = false,
                        StatusSend     = false,
                        User_Id        = User.Identity.GetUserId <int>(),
                    };

                    var orderList = new List <Order>();
                    list.ForEach(x =>
                    {
                        orderList.Add(new Order
                        {
                            Name            = x.Name,
                            Price           = x.Price,
                            Quantity        = x.Quantity,
                            StatusTypeOrder = StatusTypeOrder.EWPR.ToString(),
                            Product_Id      = x.Product_Id
                        });
                    });
                    sale.Orders = orderList;

                    _saleService.Create(sale);
                    if (_unitOfWork.SaveAllChanges() > 0)
                    {
                        HttpCookie cookieCode = new HttpCookie("TrackingNumber");
                        cookieCode.Values["Code"] = new EnDecryption().Encryption(((sale.Id * 347) + 2323).ToString());
                        cookieCode.Expires        = DateTime.Now.AddMinutes(10);
                        Response.Cookies.Add(cookieCode);

                        if (selectPayment == StatusTypePay.Online)
                        {
                            return(Json(new { Status = "true", Result = "ثبت سفارش با موفقیت صورت گرفت", Address = "Ultimate/" }, JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            return(Json(new { Status = "true", Result = "ثبت سفارش با موفقیت صورت گرفت", Address = "Ultimate/" }, JsonRequestBehavior.AllowGet));
                        }
                    }
                    else
                    {
                        return(Json(new { Status = "false", Result = "متاسفانه در ثبت سفارش خطایی رخ داده شده است مجدد صفحه را بروز رسانی کنید" }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    return(RedirectToAction(MVC.Home.ActionNames.Index, MVC.Home.Name));
                }
            }
            else
            {
                return(RedirectToAction(MVC.Home.ActionNames.Index, MVC.Home.Name));
            }
        }