Exemplo n.º 1
0
        public ActionResult Wishlist()
        {
            var cart = _userContext.CurrentUser.ShoppingCartItems
                .Where(sci => sci.ShoppingCartType == ShoppingCartType.Wishlist)
                .ToList();

            var model = new ShoppingCartModel();
            PrepareShoppingCartModel(model, cart);
            return View(model);
        }
Exemplo n.º 2
0
        protected virtual void PrepareShoppingCartModel(ShoppingCartModel model, IList<ShoppingCartItem> items)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            if (items == null)
                throw new ArgumentNullException("cart");

            if (items.Count == 0) return;

            foreach (var item in items)
            {
                var itemModel = new ShoppingCartModel.ShoppingCartItemModel()
                {
                    Id = item.Id,
                    ProductId = item.ProductId,
                    ProductName = item.Product.Name,
                    ItemPrice = item.ItemPrice,
                    Quantity = item.Quantity,
                    SubTotal = item.ItemPrice * item.Quantity,
                };

                // picture
                var picture = _pictureService.GetPicturesByProductId(itemModel.ProductId, 1).FirstOrDefault();
                int imageSize = _sysSetting.ProductDetailPicSize;

                // PictureModel
                PictureModel pictureModel = new PictureModel
                {
                    ImageUrl = _pictureService.GetPictureUrl(picture, imageSize),
                    FullSizeImageUrl = _pictureService.GetPictureUrl(picture),
                    Title = string.Format("Show detail for {0}", itemModel.ProductName),
                    AlternateText = string.Format("Image of {0}", itemModel.ProductName)
                };
                itemModel.Picture = pictureModel;
                model.Items.Add(itemModel);
            }
        }
Exemplo n.º 3
0
        public ActionResult UpdateWishList(FormCollection form)
        {
            var cart = _userContext.CurrentUser.ShoppingCartItems
                .Where(sci => sci.ShoppingCartType == ShoppingCartType.Wishlist)
                .ToList();

            var allIdsdeleting = form["removefromlist"] != null ?
                form["removefromlist"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList()
                : new List<int>();

            foreach (var cartItem in cart)
            {
                if (allIdsdeleting.Contains(cartItem.Id))
                {
                    _shoppingCartService.DeleteShoppingCartItem(cartItem);
                }
            }

            cart = _userContext.CurrentUser.ShoppingCartItems
                .Where(sci => sci.ShoppingCartType == ShoppingCartType.Wishlist)
                .ToList();

            var model = new ShoppingCartModel();
            PrepareShoppingCartModel(model, cart);
            return View(model);
        }