GuestLog - User message improvements

- Added UserMessageService to have common methods for showing messages and errors to the user.
- Added Result record so services can return status on operation error (so it can be shown in the UI messages).
- Updated services to use the new Result record.
- Updated pages to use the new IUserMessageService.
This commit is contained in:
2026-08-23 21:57:26 +02:00
parent 0de4e1ba10
commit 511bd023f2
22 changed files with 239 additions and 80 deletions
+24
View File
@@ -0,0 +1,24 @@
namespace Somnia.GuestLog.Models.DTOs;
public sealed record Result(bool IsSuccess, string ResultCode, params object[]? Context)
{
public static Result Ok() => new(IsSuccess: true, ResultCode: Models.ResultCode.Ok, Context: null);
public static Result Fail(string resultCode) => new(IsSuccess: false, resultCode, Context: null);
public static Result FailWithContext(string resultCode, params object[] context)
=> new(IsSuccess: false, resultCode, context);
public static Result FailUnknownError()
=> new(IsSuccess: false, ResultCode: Models.ResultCode.UnknownError, Context: null);
public bool IsUnknownError => !IsSuccess && ResultCode == Models.ResultCode.UnknownError;
}
public sealed record Result<T>(bool IsSuccess, T? Value, string ResultCode, params object[]? Context)
{
public static Result<T> Ok(T value) => new(IsSuccess: true, value, ResultCode: Models.ResultCode.Ok, Context: null);
public static Result<T> Fail(string resultCode) => new(IsSuccess: false, Value: default, resultCode, Context: null);
public static Result<T> FailWithContext(string resultCode, params object[] context)
=> new(IsSuccess: false, Value: default, resultCode, context);
public bool IsUnknownError => !IsSuccess && ResultCode == Models.ResultCode.UnknownError;
}
+11
View File
@@ -0,0 +1,11 @@
namespace Somnia.GuestLog.Models;
public static class ResultCode
{
public const string Ok = "Ok";
public const string UnknownError = "UnknownError";
public const string FailedValidation = "FailedValidation";
public const string NotFound = "NotFound";
public const string GuestCurrentlyInStay = "GuestCurrentlyInStay";
}