protected override async Task OnInitializedAsync()
        {
            try
            {
                Model = await Http.GetFromJsonAsync <AutoUpdateUserModel>($"api/account/info/{ModelId}");

                RequestHeaders = await HeadersProvider.CreateAsync();

                if (_options == null)
                {
                    _options = await Http.GetFromJsonAsync <IEnumerable <SelectOptionList> >("api/account/options");
                }
            }
            catch (AccessTokenNotAvailableException ex)
            {
                ex.Redirect();
            }
            catch (Exception ex)
            {
                if (Manager != null)
                {
                    Manager.SubmitResult = FormManagerSubmitResult.Failed(null, ex.ToString(), false);
                }
            }
            await base.OnInitializedAsync();
        }
Ejemplo n.º 2
0
        private async Task HandleSubmitDone(FormManagerSubmitResult result)
        {
            Manager.ProcessCustomServerResponse(result);
            if (true == Manager.SubmitResult?.Succeeded)
            {
                await Task.Delay(2000);

                NavigationManager.NavigateTo("/account/autoeditform", true);
            }
        }
 protected override async Task HandleSubmitDoneAsync(FormManagerSubmitResult result)
 {
     if (result.Succeeded)
     {
         this.ProcessCustomServerResponse(result);
         if (result.UploadContainedFiles)
         {
             await RemoteImgRef?.RefreshAsync();
         }
     }
     await base.HandleSubmitDoneAsync(result);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Custom server response handler.
        /// </summary>
        /// <param name="result">
        /// A reference to the <see cref="FormManagerBase{TModel}.SubmitResult"/> property.
        /// </param>
        private void ProcessCustomServerResponse(FormManagerSubmitResult result)
        {
            // Don't update the state because it will be done by the
            // form manager once execution of this method is finished.
            var xhr = result.XHR;

            if (xhr.IsJsonResponse)
            {
                if (IsDebug)
                {
                    Console.WriteLine($"Raw JSON result: {xhr.ResponseText}");
                }

                try
                {
                    var postResult = JsonSerializer.Deserialize <PostFormHttpResult>(
                        xhr.ResponseText,
                        CaseInsensitiveJson
                        );

                    if (postResult.Success)
                    {
                        SubmitResult = FormManagerSubmitResult.Success(result,
                                                                       postResult.Message ?? SUCCESS_MESSAGE);
                    }
                    else if (true == xhr.ExtraProperties?.ContainsKey("error"))
                    {
                        SubmitResult = FormManagerSubmitResult.Failed(result,
                                                                      xhr.ExtraProperties["error"]?.ToString());
                    }
                    else
                    {
                        SubmitResult = FormManagerSubmitResult.Failed(result,
                                                                      postResult.GetErrorDetails() ?? UNKNOWN_SUBMIT_ERROR);
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex);
                }
            }
            else if (IsDebug)
            {
                if (xhr.IsHtmlResponse)
                {
                    Console.WriteLine($"HTML result: {xhr.ResponseText}");
                }
                else
                {
                    Console.WriteLine($"Raw result: {xhr.ResponseText}");
                }
            }
        }
        /// <summary>
        /// Custom server response handler.
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="result">
        /// A reference to the <see cref="FormManagerBase{TModel}.SubmitResult"/> property.
        /// </param>
        public static void ProcessCustomServerResponse(this FormManagerBase manager, FormManagerSubmitResult result)
        {
            var xhr = result.XHR;

            if (xhr.IsJsonResponse)
            {
                try
                {
                    var postResult = JsonSerializer.Deserialize <PostFormHttpResult>(
                        xhr.ResponseText,
                        CaseInsensitiveJson
                        );

                    if (postResult.Success)
                    {
                        manager.SubmitResult = FormManagerSubmitResult.Success(result,
                                                                               postResult.Message ?? SUCCESS_MESSAGE);
                    }
                    else if (true == xhr.ExtraProperties?.ContainsKey("error"))
                    {
                        manager.SubmitResult = FormManagerSubmitResult.Failed(result,
                                                                              xhr.ExtraProperties["error"]?.ToString());
                    }
                    else
                    {
                        manager.SubmitResult = FormManagerSubmitResult.Failed(result,
                                                                              postResult.GetErrorDetails() ?? UNKNOWN_SUBMIT_ERROR);
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex);
                }
            }
            else if (manager.IsDebug && !result.Succeeded)
            {
                if (xhr.IsHtmlResponse)
                {
                    Console.WriteLine($"HTML result: {xhr.ResponseText}");
                }
                else
                {
                    Console.WriteLine($"Raw result: {xhr.ResponseText}");
                }
            }
        }
        protected override async Task OnInitializedAsync()
        {
            try
            {
                await RetrieveUserInfoAsync();

                RequestHeaders = await HeadersProvider.CreateAsync();
            }
            catch (AccessTokenNotAvailableException ex)
            {
                ex.Redirect();
            }
            catch (Exception ex)
            {
                SubmitResult = FormManagerSubmitResult.Failed(null, ex.ToString(), false);
            }
            await base.OnInitializedAsync();
        }
Ejemplo n.º 7
0
 protected override async Task OnInitializedAsync()
 {
     // This isn't an unnecessary assignment; EditForm needs an initialized Model.
     // Do the initialization before calling any asynchronous method.
     Model = new UpdateUserModel();
     try
     {
         await RetrieveUserInfoAsync();
         await SetRequestHeadersAsync();
     }
     catch (AccessTokenNotAvailableException ex)
     {
         ex.Redirect();
     }
     catch (Exception ex)
     {
         SubmitResult = FormManagerSubmitResult.Failed(null, ex.ToString(), false);
     }
     await base.OnInitializedAsync();
 }
        private void HandleSubmitDone(FormManagerSubmitResult result)
        {
            // Succeeded means the server responded with a success status code.
            // But we still have to find out how the action really came out.
            if (result.Succeeded && result.XHR.IsJsonResponse)
            {
                try
                {
                    // Since the response is in JSON format, let's parse it and investigate.
                    var response = JsonSerializer.Deserialize <RegisterUserModelResult>(
                        result.XHR.ResponseText, CaseInsensitiveJson);

                    if (!response.Success)
                    {
                        manager.SubmitResult = FormManagerSubmitResult.Failed(result, response.Error);
                    }
                    else if (!string.IsNullOrEmpty(response.Message))
                    {
                        manager.SubmitResult = FormManagerSubmitResult.Success(result, response.Message);
                        if (response.SignedIn)
                        {
                            NavigationManager.NavigateTo("/account/update", true);
                        }
                        else
                        {
                            // invalidate the form by setting a new model
                            Model = new RegisterUserModel();
                            StateHasChanged();
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex);
                }
            }
        }