Код: Выделить всё
public class Article : Entity
{
public ArticleTitle Title { private set; get; }
public ArticleMarkdownBody Body { private set; get; }
public AdminId WriterId { get; }
public Admin Writer { get; }
private Article(ArticleId id, ArticleTitle title, ArticleMarkdownBody body, AdminId writerId) : base(id)
{
Title = title;
Body = body;
WriterId = writerId;
}
public static Result Create(ArticleId id, ArticleTitle title, ArticleMarkdownBody body, DateTime creationDate, ImageSource? imageSource, AdminId writerId)
{
List errors = [];
if (id is null)
{
errors.Add(ArticleErrors.ArticleIdValueObjectWasNull);
}
if (title is null)
{
errors.Add(ArticleErrors.ArticleTitleValueObjectWasNull);
}
if (body is null)
{
errors.Add(ArticleErrors.ArticleBodyValueObjectWasNull);
}
if(writerId is null)
{
errors.Add(ArticleErrors.WriterIdWasNull);
}
if (errors.Count > 0)
{
return Result.Failure().WithErrors([.. errors]).WithMessage("The id, title, body and/or creationDate arguments sent to Article.Create were null.");
}
return Result.Success(new Article(id!, title!, body!, creationDate, imageSource, writerId!));
}
}
Код: Выделить всё
public class Admin
{
public AdminId Id { get; }
public AdminName? Name { get; private set; }
public string PasswordHash { get; private set; }
public Admin(AdminId id, AdminName name, string passwordHash)
{
Id = id;
Name = name;
PasswordHash = passwordHash;
}
abstract static Result Create(AdminId id, AdminName name, string passwordHash)
{
List errors = [];
if(string.IsNullOrEmpty(passwordHash))
{
errors.Add(AdminErrors.PasswordHashIsNullOrEmpty);
}
if (id is null)
{
errors.Add(AdminErrors.AdminIdIsNull);
}
if (name is null)
{
errors.Add(AdminErrors.AdminNameIsNull);
}
if (errors.Count != 0)
{
return Result.Failure().WithMessage("The id and/or the name argument sent in the Admin.Create method were null.").WithErrors(errors.ToArray());
}
return new Admin(id, name!);
}
}
Я не смогу сделать выбранное утверждение без настройки свойства пароля. DTO.
Подробнее здесь: https://stackoverflow.com/questions/796 ... ncluded-fr
Мобильная версия