-
-
Save StephenCleary/139f6b313788032fe9c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class AwaitableMessages | |
{ | |
public static Task<T> NextMessageAsync<T>() | |
{ | |
var tcs = new TaskCompletionSource<T>(); | |
Messenger.Default.Register<T>(null, item => tcs.TrySetResult(item)); | |
return tcs.Task; | |
} | |
} | |
namespace MongoDBApp.ViewModels | |
{ | |
[ImplementPropertyChanged] | |
public class CustomerOrdersViewModel : IPageViewModel | |
{ | |
private IDataService<OrderModel> _orderDataService; | |
public CustomerOrdersViewModel(IDataService<OrderModel> orderDataService) | |
{ | |
this._orderDataService = orderDataService; | |
this.Initialization = InitializeAsync(); | |
} | |
#region properties | |
public string SelectedCustomerEmail { get; set; } | |
public ObservableCollection<OrderModel> CustomerOrders { get; set; } | |
public Task Initialization { get; set; } | |
#endregion | |
#region methods | |
private async Task InitializeAsync() | |
{ | |
var customer = await AwaitableMessages.NextMessageAsync<CustomerModel>(); | |
SelectedCustomerEmail = customer.Email; | |
await LoadCustomerOrdersAsync(SelectedCustomerEmail); | |
IsEnabled = true; | |
} | |
public async Task LoadCustomerOrdersAsync(string email) | |
{ | |
var ordersResult = await _orderDataService.GetAllByEmailAsync(email); | |
CustomerOrders = ordersResult.ToObservableCollection(); | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment