Jarstat

Форк
0
62 строки · 1.8 Кб
1
using Jarstat.Domain.Errors;
2
using Jarstat.Domain.Primitives;
3
using Jarstat.Domain.Shared;
4
using System.Text.Json.Serialization;
5

6
namespace Jarstat.Domain.Entities;
7

8
public sealed class File : Entity
9
{
10
    private File() { }
11

12
    [JsonConstructor]
13
    public File(
14
        Guid id, 
15
        byte[] value, 
16
        DateTime dateTimeCreated, 
17
        DateTime dateTimeUpdated, 
18
        User creator, 
19
        User lastUpdater)
20
    {
21
        Id = id;
22
        Value = value;
23
        DateTimeCreated = dateTimeCreated;
24
        DateTimeUpdated = dateTimeUpdated;
25
        Creator = creator;
26
        LastUpdater = lastUpdater;
27
    }
28

29
    public byte[] Value { get; private set; } = null!;
30

31
    public static Result<File?> Create(byte[] value, User creator)
32
    {
33
        if (value is null)
34
            return Result<File?>.Failure(DomainErrors.ArgumentNullValue
35
                .WithParameters(nameof(value), typeof(byte[]).ToString()));
36

37
        if (value.Length == 0)
38
            return Result<File?>.Failure(DomainErrors.ArgumentArrayLengthIsZeroValue
39
                .WithParameters(nameof(value), typeof(byte[]).ToString()));
40

41
        if (creator is null)
42
            return Result<File?>.Failure(DomainErrors.ArgumentNullValue
43
                .WithParameters(nameof(creator), typeof(User).ToString()));
44

45
        var content = new File(Guid.NewGuid(), value, DateTime.UtcNow, DateTime.UtcNow, creator, creator);
46

47
        return 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

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.