-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModels.cs
99 lines (72 loc) · 3.2 KB
/
Models.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Identity;
using System.Collections.Generic;
using System.Linq;
public class AppUser : IdentityUser
{ }
[Table("Tasks")]
public class AppTask
{
[Key]
[JsonIgnore]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int? TaskId { get; set; }
// This prevent clients explicitly set `id` field
[JsonPropertyName("taskId")] public int? PublicTaskId => TaskId;
[Required(AllowEmptyStrings = false, ErrorMessage = "Task `Content` field must not empty or null.")]
public string Content { get; set; }
[JsonIgnore]
[DefaultValue(null)] public DateTime? DueDate { get; set; }
#nullable enable
[NotMapped]
[JsonPropertyName("dueDate")]
public string? DueDateInUnix
{
get => DueDate?.ToLocalTime().ToString();
set => DueDate = value == null ? null : DateTime.Parse(value);
}
#nullable disable
[JsonIgnore] [DefaultValue(null)] public DateTime? CompletedAt { get; set; }
[NotMapped]
[JsonPropertyName("completedAt")]
public long? CompletedAtInUnix
{
get => Utils.DateTimeToUnixTime(CompletedAt);
set => CompletedAt = Utils.UnixTimeToDateTime(value);
}
[DefaultValue(false)] public bool IsFlagged { get; set; }
[DefaultValue("")] public string Note { get; set; }
[DefaultValue(null)]
[Range(minimum: 0, maximum: 3, ErrorMessage = "{0} can only in range from 0 to 3, or empty.")]
public int? Priority { get; set; }
[JsonIgnore] public DateTime? CreationDate { get; set; }
[JsonPropertyName("creationDate")] public long? CreationDateInUnix => Utils.DateTimeToUnixTime(CreationDate);
[JsonIgnore] public DateTime? LastEdited { get; set; }
[JsonPropertyName("lastEdited")] public long? LastEditedAtInUnix => Utils.DateTimeToUnixTime(LastEdited);
public bool IsCompleted => CompletedAt != null;
[JsonIgnore] public virtual Collection Collection { get; set; }
}
public class Collection
{
#nullable enable
[JsonIgnore]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int? CollectionId { get; set; }
// This prevent clients explicitly set `id` field
[JsonPropertyName("collectionId")] public int? PublicCollectionId => CollectionId;
[JsonIgnore] public DateTime? CreationDate { get; set; }
[JsonPropertyName("creationDate")] public long? CreationDateInUnix => Utils.DateTimeToUnixTime(CreationDate);
[JsonIgnore] public DateTime? LastEdited { get; set; }
[JsonPropertyName("lastEdited")] public long? LastEditedAtInUnix => Utils.DateTimeToUnixTime(LastEdited);
[JsonIgnore] public virtual AppUser? Owner { get; set; }
#nullable disable
[Required(AllowEmptyStrings = false, ErrorMessage = "Collection `Name` field must not empty or null.")]
public string Name { get; set; }
[JsonIgnore] public virtual List<AppTask> Tasks { get; set; }
[NotMapped] public List<AppTask> CompletedTasks => Tasks?.Where(t => t.IsCompleted).ToList();
[NotMapped] public List<AppTask> IncompletedTasks => Tasks?.Where(t => !t.IsCompleted).ToList();
}