SHA256
feat StayExport - Added common Interface "IResult" for Result so both (generic and non-generic one) can be used easier.
This commit is contained in:
@@ -148,6 +148,7 @@
|
||||
|
||||
var fileName = Path.GetFileName(item.ExportedPath);
|
||||
await JS.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef);
|
||||
userMessage.ShowMessage("Exported File downloaded!", MessageKind.Success);
|
||||
}
|
||||
|
||||
private async Task BtnDeleteItem(StayExportFileDTO item)
|
||||
|
||||
@@ -125,18 +125,17 @@
|
||||
var exportResult = await exportService.ExportStaysByParams(exportParams);
|
||||
|
||||
exportedFile = exportResult.Value;
|
||||
userMessage.ShowMessage(
|
||||
$"Stay exported: {exportResult.ResultCode} with export result: {exportedFile?.ExportResult} to '{exportedFile?.ExportedPath ?? "???"}'",
|
||||
MessageKind.Info);
|
||||
|
||||
loadingDialog.Close();
|
||||
|
||||
@* Result createResult = await stayService.CreateEntryAsync(model);
|
||||
if (!createResult.IsSuccess)
|
||||
if (!exportResult.IsSuccess)
|
||||
{
|
||||
userMessage.ShowResultWithMessage(createResult, $"Error creating StayEntry");
|
||||
userMessage.ShowResultWithMessage(exportResult, $"Error exporting stays");
|
||||
return;
|
||||
} *@
|
||||
}
|
||||
|
||||
userMessage.ShowMessage(
|
||||
$"Stay exported: {exportResult.ResultCode} with export result: {exportedFile?.ExportResult}",
|
||||
MessageKind.Success);
|
||||
}
|
||||
|
||||
private async Task BtnDownloadExportedFile()
|
||||
@@ -161,6 +160,8 @@
|
||||
using var streamRef = new DotNetStreamReference(stream: objectStream);
|
||||
|
||||
await JS.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef);
|
||||
|
||||
userMessage.ShowMessage("Exported File downloaded!", MessageKind.Success);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,18 @@ using Somnia.GuestLog.Enums.Services;
|
||||
|
||||
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);
|
||||
|
||||
@@ -15,7 +26,12 @@ public sealed record Result(bool IsSuccess, ResultCode ResultCode, params object
|
||||
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> Fail(ResultCode resultCode) => new(IsSuccess: false, Value: default, resultCode, Context: null);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Somnia.GuestLog.Enums.UI;
|
||||
using Somnia.GuestLog.Models.DTOs;
|
||||
using IResult = Somnia.GuestLog.Models.DTOs.IResult;
|
||||
|
||||
namespace Somnia.GuestLog.Services;
|
||||
|
||||
@@ -7,6 +7,6 @@ public interface IUserMessageService
|
||||
{
|
||||
public void ShowMessage(string text, MessageKind kind, params object[] parameters);
|
||||
|
||||
public void ShowResult(Result resultDto);
|
||||
public void ShowResultWithMessage(Result resultDto, string message);
|
||||
public void ShowResult(IResult resultDto);
|
||||
public void ShowResultWithMessage(IResult resultDto, string message);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using MudBlazor;
|
||||
using Somnia.GuestLog.Enums.Services;
|
||||
using Somnia.GuestLog.Enums.UI;
|
||||
using Somnia.GuestLog.Models.DTOs;
|
||||
using IResult = Somnia.GuestLog.Models.DTOs.IResult;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void ShowResultWithMessage(Result resultDto, string? message)
|
||||
public void ShowResultWithMessage(IResult resultDto, string? message)
|
||||
{
|
||||
string resultMsg = GetMsgForResultCode(resultDto.ResultCode);
|
||||
resultMsg = GetFormatedMessage(resultMsg, resultDto.Context);
|
||||
|
||||
Reference in New Issue
Block a user