|
6 | 6 | using System; |
7 | 7 | using System.Linq; |
8 | 8 | using System.Threading.Tasks; |
| 9 | +using DevInstance.BlazorToolkit.Utils; |
9 | 10 |
|
10 | | -namespace NoCrast.Server.Database.Postgres.Data.Queries |
| 11 | +namespace NoCrast.Server.Database.Postgres.Data.Queries; |
| 12 | + |
| 13 | +public class CoreUserProfilesQuery : CoreBaseQuery, IUserProfilesQuery |
11 | 14 | { |
12 | | - public class CoreUserProfilesQuery : CoreBaseQuery, IUserProfilesQuery |
| 15 | + private IQueryable<UserProfile> currentQuery; |
| 16 | + |
| 17 | + private CoreUserProfilesQuery(IQueryable<UserProfile> q, IScopeManager logManager, |
| 18 | + ITimeProvider timeProvider, |
| 19 | + ApplicationDbContext dB, |
| 20 | + UserProfile currentProfile) |
| 21 | + : base(logManager, timeProvider, dB, currentProfile) |
13 | 22 | { |
14 | | - private IQueryable<UserProfile> currentQuery; |
| 23 | + currentQuery = q; |
| 24 | + } |
15 | 25 |
|
16 | | - private CoreUserProfilesQuery(IQueryable<UserProfile> q, IScopeManager logManager, |
17 | | - ITimeProvider timeProvider, |
18 | | - ApplicationDbContext dB, |
19 | | - UserProfile currentProfile) |
20 | | - : base(logManager, timeProvider, dB, currentProfile) |
21 | | - { |
22 | | - currentQuery = q; |
23 | | - } |
24 | | - |
25 | | - public CoreUserProfilesQuery(IScopeManager logManager, |
26 | | - ITimeProvider timeProvider, |
27 | | - ApplicationDbContext dB, |
28 | | - UserProfile currentProfile) |
29 | | - : this(from ts in dB.UserProfiles |
30 | | - select ts, logManager, timeProvider, dB, currentProfile) |
31 | | - { |
| 26 | + public CoreUserProfilesQuery(IScopeManager logManager, |
| 27 | + ITimeProvider timeProvider, |
| 28 | + ApplicationDbContext dB, |
| 29 | + UserProfile currentProfile) |
| 30 | + : this(from ts in dB.UserProfiles |
| 31 | + select ts, logManager, timeProvider, dB, currentProfile) |
| 32 | + { |
32 | 33 |
|
33 | | - } |
| 34 | + } |
34 | 35 |
|
35 | | - public async Task AddAsync(UserProfile record) |
36 | | - { |
37 | | - DB.UserProfiles.Add(record); |
38 | | - await DB.SaveChangesAsync(); |
39 | | - } |
| 36 | + public async Task AddAsync(UserProfile record) |
| 37 | + { |
| 38 | + DB.UserProfiles.Add(record); |
| 39 | + await DB.SaveChangesAsync(); |
| 40 | + } |
40 | 41 |
|
41 | | - public IUserProfilesQuery ByName(string name) |
42 | | - { |
43 | | - currentQuery = from pr in currentQuery |
44 | | - where pr.Name == name |
45 | | - select pr; |
| 42 | + public IUserProfilesQuery ByName(string name) |
| 43 | + { |
| 44 | + currentQuery = from pr in currentQuery |
| 45 | + where pr.Name == name |
| 46 | + select pr; |
46 | 47 |
|
47 | | - return this; |
48 | | - } |
| 48 | + return this; |
| 49 | + } |
49 | 50 |
|
50 | | - public IUserProfilesQuery ByPublicId(string id) |
51 | | - { |
52 | | - currentQuery = from pr in currentQuery |
53 | | - where pr.PublicId == id |
54 | | - select pr; |
| 51 | + public IUserProfilesQuery ByPublicId(string id) |
| 52 | + { |
| 53 | + currentQuery = from pr in currentQuery |
| 54 | + where pr.PublicId == id |
| 55 | + select pr; |
55 | 56 |
|
56 | | - return this; |
57 | | - } |
| 57 | + return this; |
| 58 | + } |
58 | 59 |
|
59 | | - public IUserProfilesQuery Clone() |
60 | | - { |
61 | | - return new CoreUserProfilesQuery(currentQuery, LogManager, TimeProvider, DB, CurrentProfile); |
62 | | - } |
| 60 | + public IUserProfilesQuery Clone() |
| 61 | + { |
| 62 | + return new CoreUserProfilesQuery(currentQuery, LogManager, TimeProvider, DB, CurrentProfile); |
| 63 | + } |
63 | 64 |
|
64 | | - public UserProfile CreateNew() |
65 | | - { |
66 | | - DateTime now = TimeProvider.CurrentTime; |
67 | | - |
68 | | - return new UserProfile |
69 | | - { |
70 | | - Id = Guid.NewGuid(), |
71 | | - PublicId = IdGenerator.New(), |
72 | | - CreateDate = now, |
73 | | - UpdateDate = now, |
74 | | - }; |
75 | | - } |
76 | | - |
77 | | - public async Task RemoveAsync(UserProfile record) |
78 | | - { |
79 | | - DB.UserProfiles.Remove(record); |
80 | | - await DB.SaveChangesAsync(); |
81 | | - } |
| 65 | + public UserProfile CreateNew() |
| 66 | + { |
| 67 | + DateTime now = TimeProvider.CurrentTime; |
82 | 68 |
|
83 | | - public IQueryable<UserProfile> Select() |
| 69 | + return new UserProfile |
84 | 70 | { |
85 | | - return (from pr in currentQuery select pr); |
86 | | - } |
| 71 | + Id = Guid.NewGuid(), |
| 72 | + PublicId = IdGenerator.New(), |
| 73 | + CreateDate = now, |
| 74 | + UpdateDate = now, |
| 75 | + }; |
| 76 | + } |
87 | 77 |
|
88 | | - public async Task UpdateAsync(UserProfile record) |
89 | | - { |
90 | | - DateTime now = TimeProvider.CurrentTime; |
| 78 | + public async Task RemoveAsync(UserProfile record) |
| 79 | + { |
| 80 | + DB.UserProfiles.Remove(record); |
| 81 | + await DB.SaveChangesAsync(); |
| 82 | + } |
| 83 | + |
| 84 | + public IQueryable<UserProfile> Select() |
| 85 | + { |
| 86 | + return (from pr in currentQuery select pr); |
| 87 | + } |
91 | 88 |
|
92 | | - record.UpdateDate = now; |
93 | | - DB.UserProfiles.Update(record); |
94 | | - await DB.SaveChangesAsync(); |
95 | | - } |
| 89 | + public async Task UpdateAsync(UserProfile record) |
| 90 | + { |
| 91 | + DateTime now = TimeProvider.CurrentTime; |
96 | 92 |
|
97 | | - public IUserProfilesQuery ByApplicationUserId(Guid id) |
98 | | - { |
99 | | - currentQuery = from pr in currentQuery |
100 | | - where pr.ApplicationUserId == id |
101 | | - select pr; |
| 93 | + record.UpdateDate = now; |
| 94 | + DB.UserProfiles.Update(record); |
| 95 | + await DB.SaveChangesAsync(); |
| 96 | + } |
102 | 97 |
|
103 | | - return this; |
104 | | - } |
| 98 | + public IUserProfilesQuery ByApplicationUserId(Guid id) |
| 99 | + { |
| 100 | + currentQuery = from pr in currentQuery |
| 101 | + where pr.ApplicationUserId == id |
| 102 | + select pr; |
105 | 103 |
|
106 | | - public IUserProfilesQuery Search(string search) |
107 | | - { |
108 | | - throw new NotImplementedException(); |
109 | | - } |
| 104 | + return this; |
| 105 | + } |
| 106 | + |
| 107 | + public IUserProfilesQuery Search(string search) |
| 108 | + { |
| 109 | + throw new NotImplementedException(); |
110 | 110 | } |
111 | 111 | } |
0 commit comments