/// <summary>
        /// Initializes a new instance of the <see cref="CartPage" /> class.
        /// </summary>
        public CartPage()
        {
            InitializeComponent();
            var cartSercice = CartDataService.Instance;

            BindingContext = new CartPageViewModel(cartSercice);
        }
        public IActionResult SaveForLaterDelete(CartPageViewModel vm)
        {
            var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            _shoppingCartData.DelteSaveToList(vm.SaveForLater.ProductId, userId);
            return(RedirectToAction("Index"));
        }
        public CartPage()
        {
            InitializeComponent();

            BindingContext = _ViewModel = new CartPageViewModel();

            NavigationBarView.FirstNameLabel.SetBinding(Label.TextProperty, "CartCounter");
        }
        public IActionResult Delete(CartPageViewModel vm)
        {
            var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var foundShoppingProduct = _shoppingCartData.FindCartProductById(vm.ShoppingCart.ProductId, userId);

            _shoppingCartData.Delete(foundShoppingProduct);
            return(RedirectToAction("Index", "Cart"));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CartPage" /> class.
        /// </summary>
        public CartPage()
        {
            InitializeComponent();
            var cartDataService = App.MockDataService
                ? TypeLocator.Resolve <ICartDataService>()
                : DataService.TypeLocator.Resolve <ICartDataService>();

            BindingContext = new CartPageViewModel(cartDataService);
        }
Example #6
0
        public CartPage(bool cartImage)
        {
            InitializeComponent();

            BindingContext = _ViewModel = new CartPageViewModel();

            NavigationBarView.FirstNameLabel.SetBinding(Label.TextProperty, "CartCounter");

            GotoCartDetailPage = true;
        }
        //public List<CartItem> CartItems { get; set; }

        public CartPage()
        {
            InitializeComponent();
            //FillCart();
            //BindingContext = this;
            BindingContext = new CartPageViewModel();

            //var asd = new CartPageViewModel();
            //asd.CartItems = CartItems;
            //BindingContext = asd;
        }
 public CartPage()
 {
     InitializeComponent();
     NavigationPage.SetHasNavigationBar(this, false);
     Title = "Cart";
     if (Device.RuntimePlatform == Device.iOS)
     {
         Icon = "CartIcon.png";
     }
     cartPageViewModel = new CartPageViewModel(Navigation, this);
     BindingContext    = cartPageViewModel;
 }
Example #9
0
        public MainPage()
        {
            ShopingPageViewModel = new ShopingPageViewModel();
            CartPageViewModel    = new CartPageViewModel();

            foreach (var si in ShopingPageViewModel.ShopItems)
            {
                si.PropertyChanged += UpdateCart;
            }

            InitializeComponent();
            BindingContext = this;
        }
        public CartPage()
        {
            var vm = new CartPageViewModel(new PageService());

            BindingContext = vm;

            vm.page = this;
            refreshlist();

            InitializeComponent();
            _grnitemlist = this.grnitemlist;
            _NoItemFound = this.NoItemFound;
        }
        public ActionResult Update(CartPage currentPage, int productId, int quantity)
        {
            var cartRepository = new CartRepository();
            var cartCookie     = this.Request.Cookies.Get("cart");

            cartRepository.Update(productId, quantity, cartCookie.Value);

            var cartItems     = cartRepository.Get(cartCookie.Value);
            var cartViewModel = new CartPageViewModel();

            cartViewModel.CurrentPage = currentPage;
            cartViewModel.CartItems   = cartItems;

            return(View("~/Views/CartPage/Index.cshtml", cartViewModel));
        }
        // GET: /<controller>/
        public async Task <IActionResult> Index(CartPageViewModel vm)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            IEnumerable <ShoppingCart> allSavedProducts = _shoppingCartData.GetAllByUser(currentUser);
            List <Product>             allSavedProduct  = new List <Product>();

            foreach (var item in allSavedProducts)
            {
                item.Product.Quantity = item.Qty;
                allSavedProduct.Add(item.Product);
            }
            vm.Products      = allSavedProduct;
            vm.totalPrice    = vm.Products.Sum(p => p.Price * p.Quantity);
            vm.SaveForLaters = _shoppingCartData.GetAllSaveForLaterByUserId(userId);
            return(View(vm));
        }
        public IActionResult SaveForLater(CartPageViewModel vm)
        {
            var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            if (_shoppingCartData.CheckIsExistedInList(vm.SaveForLater.ProductId, userId))
            {
                return(Json(new { success = false, responseText = "The attached file is not supported." }));
            }
            else
            {
                var foundShoppingProduct = _shoppingCartData.FindCartProductById(vm.SaveForLater.ProductId, userId);

                Product foundProduct     = _productData.FindProductById(vm.SaveForLater.ProductId);
                decimal totalChangePrice = (-foundShoppingProduct.Qty) * vm.ProductPrice;
                _shoppingCartData.Delete(foundShoppingProduct);
                SaveForLater foundSaveForLater = _shoppingCartData.SaveForLater(vm.SaveForLater.ProductId, userId);
                return(Json(new { success = true, list = foundSaveForLater, totalChangePrice = totalChangePrice }));
            }
        }
        public IActionResult ChangeQty(CartPageViewModel vm)
        {
            var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var foundShoppingProduct = _shoppingCartData.FindCartProductById(vm.ShoppingCart.ProductId, userId);
            var foundProduct         = _productData.FindProductById(vm.ShoppingCart.ProductId);
            var intendedChangeQty    = vm.ShoppingCart.Qty;
            var originalQty          = foundProduct.Quantity;

            if (intendedChangeQty <= originalQty)
            {
                decimal totalChangePrice = (intendedChangeQty - foundShoppingProduct.Qty) * foundProduct.Price;

                _shoppingCartData.ModifyQty(foundShoppingProduct, intendedChangeQty);
                return(Json(new { qty = intendedChangeQty, totalChangePrice = totalChangePrice, message = "success to change qty from " + originalQty + "to" + intendedChangeQty }));
            }
            else
            {
                return(Json(new { qty = originalQty, totalChangePrice = 0, message = "Sorry, We Don't have too much in stock" }));
            }
        }
        // Sets up a new cart
        public ActionResult Index(CartPage currentPage)
        {
            var cartViewModel = new CartPageViewModel();

            cartViewModel.CurrentPage = currentPage;

            var cartCookie = this.Request.Cookies.Get("cart");

            if (cartCookie == null || string.IsNullOrWhiteSpace(cartCookie.Value))
            {
                return(View("~/Views/CartPage/Index.cshtml", cartViewModel));
            }

            var cartRepository = new CartRepository();
            var cartItems      = cartRepository.Get(cartCookie.Value);

            cartViewModel.CartItems = cartItems;

            return(View("~/Views/CartPage/Index.cshtml", cartViewModel));
        }
        /// <summary>
        /// Страница для просмотра и управления содержимым корзины
        /// </summary>
        public async Task <IActionResult> Index()
        {
            CartPageViewModel CartModel;
            var cart = GetCart();

            if (cart != null)
            {
                var products = await _productService.GetProductsFromDBByIdsAsync(cart.Products.Select(p => p.ProductId));

                var totalPrice = cart.Products.Sum(p => p.Count * products.Single(pr => pr.Id == p.ProductId).Price);

                CartModel = new CartPageViewModel
                {
                    TotalPrice = totalPrice,
                    Products   = cart.Products
                                 .Select(p =>
                                         new CartItemViewModel
                    {
                        Count   = p.Count,
                        Product = products
                                  .Where(pr => pr.Id == p.ProductId)
                                  .Select(pr => new ProductViewModel
                        {
                            Id          = pr.Id,
                            Name        = pr.Name,
                            Price       = pr.Price,
                            Description = pr.About
                        }).Single()
                    }).OrderBy(p => p.Product.Id).ToList()
                };
                ModelState.Clear();
            }
            else
            {
                CartModel = CartPageViewModel.GetDefaultSet();
            }

            return(View(CartModel));
        }
Example #17
0
        public async Task <IActionResult> Cart()
        {
            AppUser user = await _userManager.GetUserAsync(User);

            Cart cart = _sqlCart.GetCart(user);

            CartPageViewModel cartPageViewModel = new CartPageViewModel();

            List <CartItemViewModel> cartViewModels = _sqlCart.GetProductsVM(cart);

            cartPageViewModel.CartItemViewModels = cartViewModels;

            //decimal sumOfPrice = cartViewModels.Sum(p => p.Price);

            int sumOfQuantity = cartViewModels.Sum(p => p.Quantity);

            cartPageViewModel.CartPrice = cart.Price;

            cartPageViewModel.CartQuantity = sumOfQuantity;

            CartItemViewModel model = new CartItemViewModel();

            return(View(cartPageViewModel));
        }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CartPage" /> class.
 /// </summary>
 public CartPage()
 {
     InitializeComponent();
     this.BindingContext = VM = CartDataService.Instance.CartPageViewModel;
     VM.Navigation       = Navigation;
 }
Example #19
0
 public CartPage()
 {
     InitializeComponent();
     BindingContext = new CartPageViewModel(Navigation);
 }