Jarstat
62 строки · 1.8 Кб
1using Jarstat.Domain.Errors;2using Jarstat.Domain.Primitives;3using Jarstat.Domain.Shared;4using System.Text.Json.Serialization;5
6namespace Jarstat.Domain.Entities;7
8public sealed class File : Entity9{
10private File() { }11
12[JsonConstructor]13public File(14Guid id,15byte[] value,16DateTime dateTimeCreated,17DateTime dateTimeUpdated,18User creator,19User lastUpdater)20{21Id = id;22Value = value;23DateTimeCreated = dateTimeCreated;24DateTimeUpdated = dateTimeUpdated;25Creator = creator;26LastUpdater = lastUpdater;27}28
29public byte[] Value { get; private set; } = null!;30
31public static Result<File?> Create(byte[] value, User creator)32{33if (value is null)34return Result<File?>.Failure(DomainErrors.ArgumentNullValue35.WithParameters(nameof(value), typeof(byte[]).ToString()));36
37if (value.Length == 0)38return Result<File?>.Failure(DomainErrors.ArgumentArrayLengthIsZeroValue39.WithParameters(nameof(value), typeof(byte[]).ToString()));40
41if (creator is null)42return Result<File?>.Failure(DomainErrors.ArgumentNullValue43.WithParameters(nameof(creator), typeof(User).ToString()));44
45var content = new File(Guid.NewGuid(), value, DateTime.UtcNow, DateTime.UtcNow, creator, creator);46
47return content;48}49
50//public Result<Content> Update(byte[] content)51//{52// if (content is null)53// return Result<Content>.Failure(DomainErrors.ArgumentNullValue);54
55// if (content.Length == 0)56// return Result<Content>.Failure(DomainErrors.ArgumentArrayLengthIsZeroValue);57
58// Value = content;59
60// return this;61//}62}
63