Replaced async void methods with async Task.

This commit is contained in:
David Britch 2017-03-20 15:51:05 +00:00
parent 561208ca81
commit 00311b45d4
3 changed files with 17 additions and 21 deletions

View File

@ -59,7 +59,7 @@ namespace eShopOnContainers.Core.ViewModels
} }
} }
public ICommand AddCommand => new Command<BasketItem>(AddItem); public ICommand AddCommand => new Command<BasketItem>(async (item) => await AddItemAsync(item));
public ICommand CheckoutCommand => new Command(async () => await CheckoutAsync()); public ICommand CheckoutCommand => new Command(async () => await CheckoutAsync());
@ -80,22 +80,22 @@ namespace eShopOnContainers.Core.ViewModels
foreach (var basketItem in basket.Items) foreach (var basketItem in basket.Items)
{ {
BadgeCount += basketItem.Quantity; BadgeCount += basketItem.Quantity;
AddBasketItem(basketItem); await AddBasketItemAsync(basketItem);
} }
} }
MessagingCenter.Unsubscribe<CatalogViewModel, CatalogItem>(this, MessengerKeys.AddProduct); MessagingCenter.Unsubscribe<CatalogViewModel, CatalogItem>(this, MessengerKeys.AddProduct);
MessagingCenter.Subscribe<CatalogViewModel, CatalogItem>(this, MessengerKeys.AddProduct, (sender, arg) => MessagingCenter.Subscribe<CatalogViewModel, CatalogItem>(this, MessengerKeys.AddProduct, async (sender, arg) =>
{ {
BadgeCount++; BadgeCount++;
AddCatalogItem(arg); await AddCatalogItemAsync(arg);
}); });
await base.InitializeAsync(navigationData); await base.InitializeAsync(navigationData);
} }
private void AddCatalogItem(CatalogItem item) private async Task AddCatalogItemAsync(CatalogItem item)
{ {
BasketItems.Add(new BasketItem BasketItems.Add(new BasketItem
{ {
@ -106,26 +106,26 @@ namespace eShopOnContainers.Core.ViewModels
Quantity = 1 Quantity = 1
}); });
ReCalculateTotal(); await ReCalculateTotalAsync();
} }
private void AddItem(BasketItem item) private async Task AddItemAsync(BasketItem item)
{ {
BadgeCount++; BadgeCount++;
AddBasketItem(item); await AddBasketItemAsync(item);
RaisePropertyChanged(() => BasketItems); RaisePropertyChanged(() => BasketItems);
} }
private void AddBasketItem(BasketItem item) private async Task AddBasketItemAsync(BasketItem item)
{ {
BasketItems.Add(item); BasketItems.Add(item);
ReCalculateTotal(); await ReCalculateTotalAsync();
} }
private async void ReCalculateTotal() private async Task ReCalculateTotalAsync()
{ {
Total = 0; Total = 0;

View File

@ -88,9 +88,9 @@ namespace eShopOnContainers.Core.ViewModels
public ICommand AddCatalogItemCommand => new Command<CatalogItem>(AddCatalogItem); public ICommand AddCatalogItemCommand => new Command<CatalogItem>(AddCatalogItem);
public ICommand FilterCommand => new Command(Filter); public ICommand FilterCommand => new Command(async () => await FilterAsync());
public ICommand ClearFilterCommand => new Command(ClearFilter); public ICommand ClearFilterCommand => new Command(async () => await ClearFilterAsync());
public override async Task InitializeAsync(object navigationData) public override async Task InitializeAsync(object navigationData)
{ {
@ -110,7 +110,7 @@ namespace eShopOnContainers.Core.ViewModels
MessagingCenter.Send(this, MessengerKeys.AddProduct, catalogItem); MessagingCenter.Send(this, MessengerKeys.AddProduct, catalogItem);
} }
private async void Filter() private async Task FilterAsync()
{ {
if (Brand == null && Type == null) if (Brand == null && Type == null)
{ {
@ -126,7 +126,7 @@ namespace eShopOnContainers.Core.ViewModels
IsBusy = false; IsBusy = false;
} }
private async void ClearFilter() private async Task ClearFilterAsync()
{ {
IsBusy = true; IsBusy = true;

View File

@ -8,14 +8,12 @@ namespace eShopOnContainers.Core.Views
{ {
public partial class CatalogView : ContentPage, IMenuContainerPage public partial class CatalogView : ContentPage, IMenuContainerPage
{ {
private FiltersView _filterView; private FiltersView _filterView = new FiltersView();
public CatalogView() public CatalogView()
{ {
InitializeComponent(); InitializeComponent();
_filterView = new FiltersView();
SlideMenu = _filterView; SlideMenu = _filterView;
MessagingCenter.Subscribe<CatalogViewModel>(this, MessengerKeys.Filter, (sender) => MessagingCenter.Subscribe<CatalogViewModel>(this, MessengerKeys.Filter, (sender) =>
@ -42,13 +40,11 @@ namespace eShopOnContainers.Core.Views
set; set;
} }
protected override void OnBindingContextChanged() protected override void OnBindingContextChanged()
{ {
base.OnBindingContextChanged(); base.OnBindingContextChanged();
if (_filterView != null) _filterView.BindingContext = BindingContext;
_filterView.BindingContext = BindingContext;
} }
private void OnFilterChanged(object sender, EventArgs e) private void OnFilterChanged(object sender, EventArgs e)