async Task PlaceOrder() { // The server will reject the submission if you're not signed in, so attempt // to sign in first if needed if (await UserState.TrySignInAsync()) { await Store.PlaceOrder(OrderState.Order, UserState.CurrentUser?.DisplayName); OrderState.ResetOrder(); UriHelper.NavigateTo("myorders"); } }
async Task PlaceOrder() { isSubmitting = true; try { var newOrderId = await HttpClient.PlaceOrder(OrderState.Order); OrderState.ResetOrder(); NavigationManager.NavigateTo($"myorders/{newOrderId}"); } catch (AccessTokenNotAvailableException ex) { ex.Redirect(); } }
protected async Task PlaceOrderAsync() { IsSubmitting = true; try { var OrderId = await OrdersClient.PlaceOrderAsync(OrderState.Order); OrderState.ResetOrder(); NavigationManager.NavigateTo($"myorders/{OrderId}", true); } catch (AccessTokenNotAvailableException ex) { ex.Redirect(); } }
async Task PlaceOrder() { isSubmitting = true; try { var newOrderId = await HttpClient.PostJsonAsync <int>("orders", OrderState.Order); OrderState.ResetOrder(); NavigationManager.NavigateTo($"myorders/{newOrderId}"); } finally { isSubmitting = false; } }
private async Task PlaceOrder() { IsSubmitting = true; try { var orderId = await Api.PlaceOrderAsync(OrderState.Order); IsSubmitting = false; OrderState.ResetOrder(); NavigationManager.NavigateTo($"myorders/{orderId}"); } catch (AccessTokenNotAvailableException ex) { ex.Redirect(); } }
async Task PlaceOrder() { isSubmitting = true; var tokenResult = await TokenProvider.RequestAccessToken(); if (tokenResult.TryGetToken(out var accessToken)) { var request = new HttpRequestMessage(HttpMethod.Post, "orders"); request.Content = JsonContent.Create(OrderState.Order); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Value); var response = await HttpClient.SendAsync(request); var newOrderId = await response.Content.ReadFromJsonAsync <int>(); OrderState.ResetOrder(); NavigationManager.NavigateTo($"myorders/{newOrderId}"); } else { NavigationManager.NavigateTo(tokenResult.RedirectUrl); } }