Refactor UpsertAsync to use ApiResult for error handling

MassDataApiClient.UpsertAsync now returns ApiResult to standardize success and error reporting, including detailed error extraction from API responses. Updated MassDataGrid.razor to handle the new result type and display error messages accordingly. Removed obsolete try-catch logic in favor of the new pattern.
This commit is contained in:
OlgunR
2026-04-15 11:27:48 +02:00
parent 7d08923444
commit 39cb63a78d
2 changed files with 34 additions and 13 deletions

View File

@@ -305,18 +305,17 @@ else
Category = editModel.Category,
StatusFlag = editModel.StatusFlag
};
try
var result = await Api.UpsertAsync(dto);
if (!result.Success)
{
var saved = await Api.UpsertAsync(dto);
infoMessage = editModel.IsNew ? "MassData angelegt." : "MassData aktualisiert.";
focusedRowKey = saved.Id;
await LoadPage(pageIndex);
}
catch (Exception ex)
{
errorMessage = $"Fehler beim Speichern: {ex.Message}";
errorMessage = result.Error ?? "Speichern fehlgeschlagen.";
e.Cancel = true;
return;
}
infoMessage = editModel.IsNew ? "MassData angelegt." : "MassData aktualisiert.";
focusedRowKey = result.Value?.Id;
await LoadPage(pageIndex);
}
private void AddValidationError(MassDataEditModel editModel, string fieldName, string message)