Пример #1
0
        private async Task LoadContent(bool is_force = false)
        {
            if (!TextEditorField.isNOEOW() && !isLoading && model != null && (is_force || (!renderHtml && has_id)))
            {
                try
                {
                    Type         type = model.GetType();
                    PropertyInfo prop = type.GetProperty(TextEditorField);
                    await Task.Delay(300);

                    await QuillHtml.LoadHTMLContent(prop.GetValue(model).ToString());

                    renderHtml = true;
                }
                catch (Exception) { Console.WriteLine("Cannot convert from text editor data"); }
            }
        }
Пример #2
0
        protected virtual async Task HandleValidSubmit()
        {
            if (formValidator != null)
            {
                formValidator.ClearErrors();
            }
            disabled = true;
            isSaved  = false;
            string             msg      = "Create successful";
            ApiResultModel <T> response = null;

            isLoading = true;
            _Loading.Show();
            bool is_action = false;

            if (!TextEditorField.isNOEOW())
            {
                var value = await QuillHtml.GetHTML();

                if (TrySetProperty(TextEditorField, value))
                {
                    Console.WriteLine(TextEditorField + " has value...");
                }
            }

            if (id.isNOEOW() || (id == "0" || id == Guid.Empty.ToString()))
            {
                is_action = true;
                response  = await _api.Post($"{(save_url.isNOEOW() ? url : save_url)}", model);
            }
            else if (has_id)
            {
                is_action = true;
                response  = await _api.Update($"{(save_url.isNOEOW() ? url : save_url)}{id}", model);

                msg = "Update successful";
            }
            if (is_action)
            {
                if (response != null)
                {
                    if (response.Status == 200 && response.Data != null)
                    {
                        model = response.Data;
                        _toastService.ShowSuccess(msg, "Completed");
                        await OnActionCompleted.InvokeAsync(true);

                        if (isReload)
                        {
                            _NavigationManager.NavigateTo(_NavigationManager.Uri);
                        }
                        isSaved = true;
                    }
                    else
                    {
                        if (formValidator != null && response.Errors != null && response.Errors.Count > 0)
                        {
                            formValidator.DisplayErrors(response.Errors);
                        }
                        _toastService.ShowWarning(response.Message, response.Title);
                    }
                }
                else
                {
                    _toastService.ShowError("Cannot save data", "Fail");
                }
            }
            else
            {
                _toastService.ShowError("Please check data format", "Fail");
            }
            isLoading = false;
            _Loading.Hide();
            if (isSaved)
            {
                if (Redirect.isNOEOW())
                {
                    await LoadContent(is_action);
                }
                else
                {
                    _NavigationManager.NavigateTo(Redirect);
                }
            }
            disabled = false;
        }