feat StayExport - Added common Interface "IResult" for Result so both (generic and non-generic one) can be used easier.

This commit is contained in:
2026-09-04 20:50:38 +02:00
parent 313a714a99
commit 058352b7f3
5 changed files with 34 additions and 15 deletions
@@ -148,6 +148,7 @@
var fileName = Path.GetFileName(item.ExportedPath); var fileName = Path.GetFileName(item.ExportedPath);
await JS.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef); await JS.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef);
userMessage.ShowMessage("Exported File downloaded!", MessageKind.Success);
} }
private async Task BtnDeleteItem(StayExportFileDTO item) private async Task BtnDeleteItem(StayExportFileDTO item)
@@ -125,18 +125,17 @@
var exportResult = await exportService.ExportStaysByParams(exportParams); var exportResult = await exportService.ExportStaysByParams(exportParams);
exportedFile = exportResult.Value; exportedFile = exportResult.Value;
userMessage.ShowMessage(
$"Stay exported: {exportResult.ResultCode} with export result: {exportedFile?.ExportResult} to '{exportedFile?.ExportedPath ?? "???"}'",
MessageKind.Info);
loadingDialog.Close(); loadingDialog.Close();
@* Result createResult = await stayService.CreateEntryAsync(model); if (!exportResult.IsSuccess)
if (!createResult.IsSuccess)
{ {
userMessage.ShowResultWithMessage(createResult, $"Error creating StayEntry"); userMessage.ShowResultWithMessage(exportResult, $"Error exporting stays");
return; return;
} *@ }
userMessage.ShowMessage(
$"Stay exported: {exportResult.ResultCode} with export result: {exportedFile?.ExportResult}",
MessageKind.Success);
} }
private async Task BtnDownloadExportedFile() private async Task BtnDownloadExportedFile()
@@ -161,6 +160,8 @@
using var streamRef = new DotNetStreamReference(stream: objectStream); using var streamRef = new DotNetStreamReference(stream: objectStream);
await JS.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef); await JS.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef);
userMessage.ShowMessage("Exported File downloaded!", MessageKind.Success);
} }
} }
+18 -2
View File
@@ -2,7 +2,18 @@ using Somnia.GuestLog.Enums.Services;
namespace Somnia.GuestLog.Models.DTOs; namespace Somnia.GuestLog.Models.DTOs;
public sealed record Result(bool IsSuccess, ResultCode ResultCode, params object[]? Context) public interface IResult
{
bool IsSuccess { get; }
ResultCode ResultCode { get; }
object[]? Context { get; }
}
public sealed record Result(
bool IsSuccess,
ResultCode ResultCode,
params object[]? Context
) : IResult
{ {
public static Result Ok() => new(IsSuccess: true, ResultCode: ResultCode.Ok, Context: null); public static Result Ok() => new(IsSuccess: true, ResultCode: ResultCode.Ok, Context: null);
@@ -15,7 +26,12 @@ public sealed record Result(bool IsSuccess, ResultCode ResultCode, params object
public bool IsUnknownError => !IsSuccess && ResultCode == ResultCode.UnknownError; public bool IsUnknownError => !IsSuccess && ResultCode == ResultCode.UnknownError;
} }
public sealed record Result<T>(bool IsSuccess, T? Value, ResultCode ResultCode, params object[]? Context) public sealed record Result<T>(
bool IsSuccess,
T? Value,
ResultCode ResultCode,
params object[]? Context
) : IResult
{ {
public static Result<T> Ok(T value) => new(IsSuccess: true, value, ResultCode: ResultCode.Ok, Context: null); public static Result<T> Ok(T value) => new(IsSuccess: true, value, ResultCode: ResultCode.Ok, Context: null);
public static Result<T> Fail(ResultCode resultCode) => new(IsSuccess: false, Value: default, resultCode, Context: null); public static Result<T> Fail(ResultCode resultCode) => new(IsSuccess: false, Value: default, resultCode, Context: null);
@@ -1,5 +1,5 @@
using Somnia.GuestLog.Enums.UI; using Somnia.GuestLog.Enums.UI;
using Somnia.GuestLog.Models.DTOs; using IResult = Somnia.GuestLog.Models.DTOs.IResult;
namespace Somnia.GuestLog.Services; namespace Somnia.GuestLog.Services;
@@ -7,6 +7,6 @@ public interface IUserMessageService
{ {
public void ShowMessage(string text, MessageKind kind, params object[] parameters); public void ShowMessage(string text, MessageKind kind, params object[] parameters);
public void ShowResult(Result resultDto); public void ShowResult(IResult resultDto);
public void ShowResultWithMessage(Result resultDto, string message); public void ShowResultWithMessage(IResult resultDto, string message);
} }
@@ -2,6 +2,7 @@ using MudBlazor;
using Somnia.GuestLog.Enums.Services; using Somnia.GuestLog.Enums.Services;
using Somnia.GuestLog.Enums.UI; using Somnia.GuestLog.Enums.UI;
using Somnia.GuestLog.Models.DTOs; using Somnia.GuestLog.Models.DTOs;
using IResult = Somnia.GuestLog.Models.DTOs.IResult;
namespace Somnia.GuestLog.Services; namespace Somnia.GuestLog.Services;
@@ -17,12 +18,12 @@ public class UserMessageService(
} }
public void ShowResult(Result resultDto) public void ShowResult(IResult resultDto)
{ {
ShowResultWithMessage(resultDto, message: null); ShowResultWithMessage(resultDto, message: null);
} }
public void ShowResultWithMessage(Result resultDto, string? message) public void ShowResultWithMessage(IResult resultDto, string? message)
{ {
string resultMsg = GetMsgForResultCode(resultDto.ResultCode); string resultMsg = GetMsgForResultCode(resultDto.ResultCode);
resultMsg = GetFormatedMessage(resultMsg, resultDto.Context); resultMsg = GetFormatedMessage(resultMsg, resultDto.Context);