Esempio n. 1
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"));
            }
        }
Esempio n. 2
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"));
            }
        }
 private void NotifyCommands()
 {
     CancelCommand.RaiseCanExecuteChanged();
     CheckoutCommand.RaiseCanExecuteChanged();
     PrintCommand.RaiseCanExecuteChanged();
     PreviewCommand.RaiseCanExecuteChanged();
     SearchProductCommand.RaiseCanExecuteChanged();
 }