protected virtual async Task HandleDelete() { if (!id.isNOEOW() && (!id.isNumberic() || !id.IsGuid())) { isLoading = true; var response = await _api.Delete($"{url}{id}"); if (response != null) { if (response.Status == 200 && response.Data) { _toastService.ShowSuccess("The data was deleted", "Completed"); await OnActionCompleted.InvokeAsync(true); if (!Redirect.isNOEOW()) { _NavigationManager.NavigateTo(Redirect); } else if (isReload) { _NavigationManager.NavigateTo(UrlHelper.GetAbsolutePath(_NavigationManager.Uri)); } await modal.Close(); } else { _toastService.ShowWarning(response.Message, "Failed"); await OnActionCompleted.InvokeAsync(false); } } else { _toastService.ShowError($"Fial to remove: {id}", "Failed"); await OnActionCompleted.InvokeAsync(false); } isLoading = false; } }
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; }