implement
This commit is contained in:
@@ -18,6 +18,11 @@ public abstract class DomainModel<TId> where TId : DomainId
|
||||
Id = id;
|
||||
}
|
||||
|
||||
public string GetModelName()
|
||||
{
|
||||
return this.GetType().Name;
|
||||
}
|
||||
|
||||
public IReadOnlyList<IDomainEvent> GetDomainEvents() => _domainEvents.ToList();
|
||||
|
||||
public void ClearDomainEvents() => _domainEvents.Clear();
|
||||
|
||||
38
dotnet/AipsCore/Domain/Abstract/Validation/AbstractErrors.cs
Normal file
38
dotnet/AipsCore/Domain/Abstract/Validation/AbstractErrors.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using AipsCore.Domain.Common.Validation;
|
||||
using AipsCore.Domain.Common.ValueObjects;
|
||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
namespace AipsCore.Domain.Abstract.Validation;
|
||||
|
||||
public abstract class AbstractErrors<TModel, TId>
|
||||
where TModel : DomainModel<TId>
|
||||
where TId : DomainId
|
||||
{
|
||||
public static string GetModelName()
|
||||
{
|
||||
return typeof(TModel).Name;
|
||||
}
|
||||
|
||||
public static string Prefix()
|
||||
{
|
||||
return GetModelName().ToLower();
|
||||
}
|
||||
|
||||
protected static string GetFullCode(string code)
|
||||
{
|
||||
return $"{Prefix()}_{code}";
|
||||
}
|
||||
|
||||
protected static ValidationError CreateValidationError(string code, string errorMessage)
|
||||
{
|
||||
return new ValidationError(GetFullCode(code), errorMessage);
|
||||
}
|
||||
|
||||
public static ValidationError NotFound(TId id)
|
||||
{
|
||||
const string code = "not_found";
|
||||
string message = $"{GetModelName()} with id '{id}' was not found!";
|
||||
|
||||
return CreateValidationError(code,message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user