コード例 #1
0
ファイル: AppHelpers.cs プロジェクト: kaisermtv/WebMvc
        public static string GetJsonShoppingCart()
        {
            Hashtable list = null;

            try
            {
                list = (Hashtable)HttpContext.Current.Session["SopiingCart"];
            }
            catch { }

            if (list == null)
            {
                list = new Hashtable();
                HttpContext.Current.Session["SopiingCart"] = list;
            }

            var viewModel = new CartListViewModel();

            viewModel.Count = list.Count;

            viewModel.Products = new List <CartItemViewModel>();
            foreach (DictionaryEntry it in list)
            {
                viewModel.Products.Add((CartItemViewModel)it.Value);
            }

            return(JsonConvert.SerializeObject(viewModel));
        }
コード例 #2
0
        /// <summary>
        /// Gets the current users carts
        /// </summary>
        /// <param name="customerId">Current user id</param>
        /// <returns>A list of the users carts</returns>
        public CartListViewModel GetUserCartList(Guid customerId)
        {
            CartListViewModel cartList = new CartListViewModel();

            List <CartInfoViewModel> carts = new List <CartInfoViewModel>();

            Customer customer = _repo.GetCustomerById(customerId);

            if (customer == null)
            {
                return(null);
            }

            List <Order> customerCarts = _repo.GetCartsByCustomerId(customer.CustomerID);

            foreach (Order cart in customerCarts)
            {
                List <OrderLineDetails> orderLineDetails = _repo.GetOrderLineListByCart(cart);
                cart.ProductsInOrder = orderLineDetails;
                carts.Add(_mapper.ConvertOrderToCartInfoViewModel(cart));
            }

            cartList.CurrentCarts = carts;

            return(cartList);
        }
コード例 #3
0
        /// <summary>
        /// Gets a list of a users completed orders
        /// </summary>
        /// <param name="customerId">Current user</param>
        /// <returns>List of customers orders</returns>
        public CartListViewModel GetUserPastOrders(Guid customerId)
        {
            CartListViewModel orderList = new CartListViewModel();

            List <CartInfoViewModel> orders = new List <CartInfoViewModel>();

            Customer customer = _repo.GetCustomerById(customerId);

            if (customer == null)
            {
                return(null);
            }

            List <Order> customerOrders = _repo.GetOrdersByCustomerId(customer.CustomerID);

            foreach (Order order in customerOrders)
            {
                List <OrderLineDetails> orderLineDetails = _repo.GetOrderLineListByCart(order);
                order.ProductsInOrder = orderLineDetails;
                orders.Add(_mapper.ConvertOrderToCartInfoViewModel(order));
            }

            orderList.CurrentCarts = orders;

            return(orderList);
        }
コード例 #4
0
        /// <summary>
        /// Gets a list of a stores completed orders
        /// </summary>
        /// <param name="StoreId">Store id we want to look at</param>
        /// <returns>A list of orders by store id</returns>
        public CartListViewModel GetStorePastOrders(Guid StoreId)
        {
            CartListViewModel orderList = new CartListViewModel();

            List <CartInfoViewModel> orders = new List <CartInfoViewModel>();

            StoreLocation store = _repo.GetStoreById(StoreId);

            if (store == null)
            {
                return(null);
            }

            List <Order> storeOrders = _repo.GetOrdersByStoreId(store.StoreLocationId);

            foreach (Order order in storeOrders)
            {
                List <OrderLineDetails> orderLineDetails = _repo.GetOrderLineListByCart(order);
                order.ProductsInOrder = orderLineDetails;

                orders.Add(_mapper.ConvertOrderToCartInfoViewModel(order));
            }

            orderList.CurrentCarts = orders;

            return(orderList);
        }
コード例 #5
0
        public IActionResult GetCartList()
        {
            List <CartItem>   cart      = cartServices.GetCartList(UserName);
            CartListViewModel viewModel = new CartListViewModel();

            if (cart != null)
            {
                viewModel.CartItems = cart
                                      .Select(x => new CartViewModel()
                {
                    Id           = x.Id,
                    ImageAddress = x.Product.PictureAddress,
                    Price        = x.Product.Price,
                    Quantity     = x.Quantity,
                    Title        = x.Product.Title
                }).ToList();
                viewModel.TotalPrice = cart.Sum(x => x.Quantity * x.Product.Price);
            }
            else
            {
                viewModel = new CartListViewModel()
                {
                    CartItems  = new List <CartViewModel>(),
                    TotalPrice = 0
                };
            }
            return(Json(viewModel));
        }
コード例 #6
0
        public IActionResult CartList()
        {
            var cartList = new CartListViewModel {
                cart = GetCart()
            };

            return(View(cartList));
        }
コード例 #7
0
        public ViewViewComponentResult Invoke()
        {
            var model = new CartListViewModel()
            {
                Cart = _cartSessionHelper.GetCart(CartController.CartKey)
            };

            return(View(model));
        }
コード例 #8
0
        public ViewViewComponentResult Invoke()
        {
            var model = new CartListViewModel
            {
                Cart = _cartSessionHelper.GetCart("cart")
            };

            return(View(model));
        }
コード例 #9
0
        public IActionResult Index()
        {
            var model = new CartListViewModel
            {
                Cart = cartSessionHelper.GetCart(key: "cart")
            };

            return(View(model));
        }
コード例 #10
0
        public IActionResult Checkout()
        {
            var model = new CartListViewModel
            {
                Cart = _cartSessionHelper.GetCart("cart")
            };

            return(View(model));
        }
コード例 #11
0
        //burada Invoke diyip modeli içine basıyorum
        public ViewViewComponentResult Invoke()
        {
            var model = new CartListViewModel
            {
                Cart = _cartSessionService.GetCart()
            };

            return(View(model));
        }
コード例 #12
0
        public IActionResult Index()
        {
            CartListViewModel cartListViewModel = new CartListViewModel()
            {
                Cart = _cartSessionHelper.GetCart("cart")
            };

            return(View(cartListViewModel));
        }
コード例 #13
0
        public IActionResult Index()
        {
            var cart  = _cartSessionHelper.GetCart(CartKey);
            var model = new CartListViewModel()
            {
                Cart = cart
            };

            return(View(model));
        }
コード例 #14
0
        public IActionResult List()
        {
            var cart = _sessionService.GetCart();
            CartListViewModel model = new CartListViewModel()
            {
                Cart = cart,
            };

            return(View(model));
        }
コード例 #15
0
        public ActionResult List()
        {
            var cart = _cartSessionService.GetCart();
            CartListViewModel cartListViewModel = new CartListViewModel
            {
                Cart = cart
            };

            return(View(cartListViewModel));
        }
コード例 #16
0
        public ActionResult List()
        {
            var cart = _cartSessionService.GetCart();
            // CartLİstViewMOdel e  ihtiyacım var
            CartListViewModel model = new CartListViewModel {
                Cart = cart
            };

            return(View(model));
        }
コード例 #17
0
        public ActionResult Index()
        {
            var viewModel = new CartListViewModel();
            var list      = GetShoppingCart();
            //viewModel.Products = GetSopiingCart();

            var pricmodel      = _productSevice.GetAttribute("Price");
            var Guaranteemodel = _productSevice.GetAttribute("Guarantee");

            viewModel.Count    = list.Count;
            viewModel.Products = new List <CartItemViewModel>();
            foreach (DictionaryEntry it in list)
            {
                CartItemViewModel item = (CartItemViewModel)it.Value;

                var pr = _productSevice.Get(item.Id);
                if (pr != null)
                {
                    viewModel.Products.Add(item);

                    item.Image = pr.Image;
                    item.link  = AppHelpers.ProductUrls(pr.Category_Id, pr.Slug);

                    var Guarante = _productSevice.GetAttributeValue(item.Id, Guaranteemodel.Id);
                    if (Guarante != null)
                    {
                        item.Guarantee = Guarante.Value;
                    }

                    var price = _productSevice.GetAttributeValue(item.Id, pricmodel.Id);
                    if (price != null)
                    {
                        try
                        {
                            int p = int.Parse(price.Value);
                            item.Priceint         = p;
                            item.Price            = p.ToString("N0").Replace(",", ".") + " VND";
                            viewModel.TotalMoney += p * item.Count;
                        }
                        catch
                        {
                            item.Price = "Liên hệ";
                        }
                    }
                    else
                    {
                        item.Price = "Liên hệ";
                    }
                }
            }

            return(View(viewModel));
        }
コード例 #18
0
        public ActionResult SuccessPay()
        {
            int customerId = (int)Session["id"];
            var ordereds   = _orderedService.GetAll().Where(x => x.CustomerID == customerId).ToList();

            CartListViewModel model = new CartListViewModel()
            {
                Ordereds = ordereds
            };

            return(View(model));
        }
コード例 #19
0
        public IActionResult ViewStorePastOrders(Guid StoreId)
        {
            CartListViewModel orderList = _logic.GetStorePastOrders(StoreId);

            if (orderList == null)
            {
                ModelState.AddModelError("Failure", "Store does not exist ");
                return(View(orderList));
            }

            return(View(orderList));
        }
コード例 #20
0
        public ActionResult Checkout()
        {
            if (Session["MovieList"] != null)
            {
                List <int>        movieIdList   = (List <int>)Session["MovieList"];
                List <Movie>      movieList     = GetCartMovies(movieIdList);
                CartListViewModel displayedCart = new CartListViewModel();

                return(View(ArrangeCart(movieList, displayedCart)));
            }
            return(RedirectToAction("Index", "Movies"));
        }
コード例 #21
0
        public async Task <ViewResult> Index()
        {
            cart.ListCartItems = await cart.GetCartItems();

            var obj = new CartListViewModel
            {
                Cart        = cart,
                SumCartItem = cart.SumCartItem()
            };

            return(View(obj));
        }
コード例 #22
0
        // GET: Checkout
        public ActionResult Index()
        {
            int id                  = (int)Session["id"];
            var customer            = _customerService.GetByIdUser(id);
            CartListViewModel model = new CartListViewModel()
            {
                Carts    = (List <Cart>)Session["sepet"],
                Ordered  = new Ordered(),
                Customer = customer
            };

            return(View(model));
        }
コード例 #23
0
        public ActionResult List()
        {
            if (_cartSessionService.GetCart().CartLines.Count <= 0)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var model = new CartListViewModel
            {
                Cart = _cartSessionService.GetCart()
            };

            return(View(model));
        }
コード例 #24
0
        public JsonResult addVariant(Guid Id, int num)
        {
            var viewModel = new CartListViewModel();
            var list      = GetShoppingCart();

            //viewModel.Products = GetSopiingCart();

            if (!list.ContainsKey(Id.ToString()))
            {
                var product = _productSevice.Get(Id);

                if (product != null)
                {
                    var a = new CartItemViewModel
                    {
                        name  = product.Name,
                        Count = num,
                        Id    = product.Id,
                    };

                    list.Add(a.Id.ToString(), a);
                    viewModel.Count = list.Count;

                    viewModel.State = 1;
                }
                else
                {
                    viewModel.State   = 0;
                    viewModel.Message = "Không tìm thấy sản phẩm!";
                }
            }
            else
            {
                ((CartItemViewModel)list[Id.ToString()]).Count = num;
                viewModel.State = 1;
            }

            viewModel.Products = new List <CartItemViewModel>();
            foreach (DictionaryEntry it in list)
            {
                viewModel.Products.Add((CartItemViewModel)it.Value);
            }


            return(Json(viewModel));
        }
コード例 #25
0
        public ActionResult Checkout(CartListViewModel vwCartList)
        {
            int custIdExists = CheckCustExists(vwCartList.Email);

            if (custIdExists == 0)
            {
                ViewBag.Message = "Email is not registered, Please try again.";
                List <int>        movieIdList   = (List <int>)Session["MovieList"];
                List <Movie>      movieList     = GetCartMovies(movieIdList);
                CartListViewModel displayedCart = new CartListViewModel();

                return(View(ArrangeCart(movieList, displayedCart)));
            }
            else
            {
                return(RedirectToAction("Create", "Order", new { custId = custIdExists }));
            }
        }
コード例 #26
0
        public async Task <IActionResult> Index()
        {
            try
            {
                int?UserId = HttpContext.Session.GetInt32("UserId");
                if (UserId != null && UserId != 0)
                {
                    CartListViewModel data = await this._cartService.GetAllCartItem(UserId);

                    if (data != null)
                    {
                        return(View(data));
                    }
                }
                return(RedirectToAction("LogIn", "Account"));
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #27
0
        private object ArrangeCart(List <Movie> movieList, CartListViewModel displayedCart)
        {
            bool foundMovie = false;

            displayedCart.CartMovies.Add(new CartMovieViewModel()
            {
                Title             = movieList[0].Title,
                Price             = movieList[0].Price,
                CopyAmount        = 1,
                TotalPriceOfMovie = movieList[0].Price,
            });
            displayedCart.TotalPriceInCart = movieList[0].Price;

            for (int i = 1; i < movieList.Count; i++)
            {
                foreach (var item in displayedCart.CartMovies)
                {
                    if (item.Title == movieList[i].Title && foundMovie == false)
                    {
                        item.CopyAmount                += 1;
                        item.TotalPriceOfMovie         += item.Price;
                        displayedCart.TotalPriceInCart += item.Price;
                        foundMovie = true;
                    }
                }
                if (foundMovie == false)
                {
                    displayedCart.CartMovies.Add(new CartMovieViewModel()
                    {
                        Title             = movieList[i].Title,
                        Price             = movieList[i].Price,
                        CopyAmount        = 1,
                        TotalPriceOfMovie = movieList[i].Price
                    });
                    displayedCart.TotalPriceInCart += movieList[i].Price;
                }
                foundMovie = false;
            }
            return(displayedCart);
        }
コード例 #28
0
        public async Task <IActionResult> Index()
        {
            string tempCartId             = httpContextAccessor.HttpContext.Request.Cookies["tempCartId"];
            List <TempCartItem> tempCarts = cartServices.GetTempCartList(tempCartId);

            if (tempCarts != null)
            {
                foreach (TempCartItem item in tempCarts)
                {
                    cartServices.addToCart(UserName, item.Product.Id, item.Quantity);
                }
                await cartServices.DeleteTempCart(tempCartId);
            }
            List <CartItem>   cart      = cartServices.GetCartList(UserName);
            CartListViewModel viewModel = new CartListViewModel();

            if (cart != null)
            {
                viewModel.CartItems = cart
                                      .Select(x => new CartViewModel()
                {
                    Id           = x.Id,
                    ImageAddress = x.Product.PictureAddress,
                    Price        = x.Product.Price,
                    Quantity     = x.Quantity,
                    Title        = x.Product.Title
                }).ToList();
                viewModel.TotalPrice = cart.Sum(x => x.Quantity * x.Product.Price);
            }
            else
            {
                viewModel = new CartListViewModel()
                {
                    CartItems  = new List <CartViewModel>(),
                    TotalPrice = 0
                };
            }
            return(View(viewModel));
        }
コード例 #29
0
        public JsonResult SetListProduct(CartListProductViewModel post)
        {
            var viewModel = new CartListViewModel();
            var list      = GetShoppingCart();

            list.Clear();

            foreach (var it in post.Products)
            {
                if (!list.ContainsKey(it.Id.ToString()))
                {
                    var product = _productSevice.Get(it.Id);

                    if (product != null)
                    {
                        var a = new CartItemViewModel
                        {
                            name  = product.Name,
                            Count = it.Count,
                            Id    = product.Id,
                        };

                        list.Add(a.Id.ToString(), a);
                        viewModel.Count = list.Count;
                    }
                }
            }

            viewModel.State    = 1;
            viewModel.Products = new List <CartItemViewModel>();
            foreach (DictionaryEntry it in list)
            {
                viewModel.Products.Add((CartItemViewModel)it.Value);
            }


            return(Json(viewModel));
        }
コード例 #30
0
        public JsonResult removeItem(Guid Id)
        {
            var viewModel = new CartListViewModel();
            var list      = GetShoppingCart();

            //viewModel.Products = GetSopiingCart();

            if (list.ContainsKey(Id.ToString()))
            {
                list.Remove(Id.ToString());
                viewModel.Count = list.Count;

                viewModel.State = 1;
            }

            viewModel.Products = new List <CartItemViewModel>();
            foreach (DictionaryEntry it in list)
            {
                viewModel.Products.Add((CartItemViewModel)it.Value);
            }


            return(Json(viewModel));
        }