Example #1
0
        private async Task Remove(ShoppingCartItemViewModel item)
        {
            if (item == null)
            {
                return;
            }

            string errorMessage = string.Empty;

            try
            {
                // Hide the AppBar
                IsBottomAppBarOpened = false;

                await _shoppingCartRepository.RemoveShoppingCartItemAsync(item.Id);

                ShoppingCartItemViewModels.Remove(item);

                CheckoutCommand.RaiseCanExecuteChanged();
                RaisePropertyChanged(nameof(FullPrice));
                RaisePropertyChanged(nameof(TotalDiscount));
                RaisePropertyChanged(nameof(TotalPrice));
            }
            catch (Exception ex)
            {
                errorMessage = string.Format(CultureInfo.CurrentCulture, _resourceLoader.GetString("GeneralServiceErrorMessage"), Environment.NewLine, ex.Message);
            }

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                await _alertMessageService.ShowAsync(errorMessage, _resourceLoader.GetString("ErrorServiceUnreachable"));
            }
        }
Example #2
0
        private async Task UpdateShoppingCartInfoAsync()
        {
            string errorMessage = string.Empty;

            try
            {
                _shoppingCart = await _shoppingCartRepository.GetShoppingCartAsync();

                if (_shoppingCart != null && _shoppingCart.ShoppingCartItems != null)
                {
                    ShoppingCartItemViewModels = new ObservableCollection <ShoppingCartItemViewModel>();
                    foreach (var item in _shoppingCart.ShoppingCartItems)
                    {
                        var shoppingCartItemViewModel = new ShoppingCartItemViewModel(item, _resourceLoader);
                        shoppingCartItemViewModel.PropertyChanged += ShoppingCartItemViewModel_PropertyChanged;
                        ShoppingCartItemViewModels.Add(shoppingCartItemViewModel);
                    }

                    CheckoutCommand.RaiseCanExecuteChanged();
                    RaisePropertyChanged(nameof(FullPrice));
                    RaisePropertyChanged(nameof(TotalDiscount));
                    RaisePropertyChanged(nameof(TotalPrice));
                }
            }
            catch (Exception ex)
            {
                errorMessage = string.Format(CultureInfo.CurrentCulture, _resourceLoader.GetString("GeneralServiceErrorMessage"), Environment.NewLine, ex.Message);
            }

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                await _alertMessageService.ShowAsync(errorMessage, _resourceLoader.GetString("ErrorServiceUnreachable"));
            }
        }
        private void FillWithDummyData()
        {
            FullPrice = "$100.50";
            TotalDiscount = "$10.50";
            TotalPrice = "$90.00";

            ShoppingCartItemViewModels = new ObservableCollection<ShoppingCartItemViewModel>()
                {
                    new ShoppingCartItemViewModel(new ShoppingCartItem()
                        {
                            Id = Guid.NewGuid().ToString(),
                            Product = new Product() { Title = "Product 1",  Description = "Description of Product 1", ListPrice = 25.10, DiscountPercentage = 10, ProductNumber = "1", ImageUri = new Uri("ms-appx:///Assets/StoreLogo.png") },
                            Quantity = 1,
                            Currency = "USD"
                        }, 
                        null),
                   new ShoppingCartItemViewModel(new ShoppingCartItem()
                        {
                            Id = Guid.NewGuid().ToString(),
                            Product = new Product() { Title = "Product 2",  Description = "Description of Product 2", ListPrice = 25.10, DiscountPercentage = 10, ProductNumber = "2", ImageUri = new Uri("ms-appx:///Assets/StoreLogo.png") },
                            Quantity = 20,
                            Currency = "USD"
                        }, 
                        null), 
                   new ShoppingCartItemViewModel(new ShoppingCartItem()
                        {
                            Id = Guid.NewGuid().ToString(),
                            Product = new Product() { Title = "Product 3",  Description = "Description of Product 3", ListPrice = 25.10, DiscountPercentage = 10, ProductNumber = "3", ImageUri = new Uri("ms-appx:///Assets/StoreLogo.png") },
                            Quantity = 30,
                            Currency = "USD"
                        }, 
                        null), 
                   new ShoppingCartItemViewModel(new ShoppingCartItem()
                        {
                            Id = Guid.NewGuid().ToString(),
                            Product = new Product() { Title = "Product 4",  Description = "Description of Product 4", ListPrice = 25.10, DiscountPercentage = 10, ProductNumber = "4", ImageUri = new Uri("ms-appx:///Assets/StoreLogo.png") },
                            Quantity = 14,
                            Currency = "USD"
                        }, 
                        null), 
                   new ShoppingCartItemViewModel(new ShoppingCartItem()
                        {
                            Id = Guid.NewGuid().ToString(),
                            Product = new Product() { Title = "Product 5",  Description = "Description of Product 5", ListPrice = 25.10, DiscountPercentage = 10, ProductNumber = "5", ImageUri = new Uri("ms-appx:///Assets/StoreLogo.png") },
                            Quantity = 25,
                            Currency = "USD"
                        }, 
                        null), 
                };

            SelectedItem = ShoppingCartItemViewModels[0];
        }
        private async Task Remove(ShoppingCartItemViewModel item)
        {
            if (item == null)
            {
                return;
            }

            string errorMessage = string.Empty;
            try
            {
                // Hide the AppBar
                IsBottomAppBarOpened = false;

                await _shoppingCartRepository.RemoveShoppingCartItemAsync(item.Id);
                ShoppingCartItemViewModels.Remove(item);

                CheckoutCommand.RaiseCanExecuteChanged();
                OnPropertyChanged("FullPrice");
                OnPropertyChanged("TotalDiscount");
                OnPropertyChanged("TotalPrice");
            }
            catch (Exception ex)
            {
                errorMessage = string.Format(CultureInfo.CurrentCulture, _resourceLoader.GetString("GeneralServiceErrorMessage"), Environment.NewLine, ex.Message);
            }

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                await _alertMessageService.ShowAsync(errorMessage, _resourceLoader.GetString("ErrorServiceUnreachable"));
            }
        }
        private async Task UpdateShoppingCartInfoAsync()
        {
            string errorMessage = string.Empty;

            try
            {
                _shoppingCart = await _shoppingCartRepository.GetShoppingCartAsync();

                if (_shoppingCart != null && _shoppingCart.ShoppingCartItems != null)
                {
                    ShoppingCartItemViewModels = new ObservableCollection<ShoppingCartItemViewModel>();
                    foreach (var item in _shoppingCart.ShoppingCartItems)
                    {
                        var shoppingCartItemViewModel = new ShoppingCartItemViewModel(item, _resourceLoader);
                        shoppingCartItemViewModel.PropertyChanged += ShoppingCartItemViewModel_PropertyChanged;
                        ShoppingCartItemViewModels.Add(shoppingCartItemViewModel);
                    }

                    CheckoutCommand.RaiseCanExecuteChanged();
                    OnPropertyChanged("FullPrice");
                    OnPropertyChanged("TotalDiscount");
                    OnPropertyChanged("TotalPrice");
                }
            }
            catch (Exception ex)
            {
                errorMessage = string.Format(CultureInfo.CurrentCulture, _resourceLoader.GetString("GeneralServiceErrorMessage"), Environment.NewLine, ex.Message);
            }

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                await _alertMessageService.ShowAsync(errorMessage, _resourceLoader.GetString("ErrorServiceUnreachable"));
            }
        }