aboutsummaryrefslogtreecommitdiff
path: root/VNLib.Plugins.Essentials.Accounts.Admin/Model
diff options
context:
space:
mode:
authorLibravatar vman <public@vaughnnugent.com>2022-11-18 16:08:51 -0500
committerLibravatar vman <public@vaughnnugent.com>2022-11-18 16:08:51 -0500
commit526c2364b9ad685d1c000fc8a168bf1305aaa8b7 (patch)
treea2bc01607320a6a75e1a869d5bd34e79fd63c595 /VNLib.Plugins.Essentials.Accounts.Admin/Model
parent2080400119be00bdc354f3121d84ec2f89606ac7 (diff)
Add project files.
Diffstat (limited to 'VNLib.Plugins.Essentials.Accounts.Admin/Model')
-rw-r--r--VNLib.Plugins.Essentials.Accounts.Admin/Model/User.cs26
-rw-r--r--VNLib.Plugins.Essentials.Accounts.Admin/Model/UserContext.cs17
-rw-r--r--VNLib.Plugins.Essentials.Accounts.Admin/Model/UserStore.cs48
3 files changed, 91 insertions, 0 deletions
diff --git a/VNLib.Plugins.Essentials.Accounts.Admin/Model/User.cs b/VNLib.Plugins.Essentials.Accounts.Admin/Model/User.cs
new file mode 100644
index 0000000..866cff1
--- /dev/null
+++ b/VNLib.Plugins.Essentials.Accounts.Admin/Model/User.cs
@@ -0,0 +1,26 @@
+using System;
+using System.ComponentModel.DataAnnotations.Schema;
+
+using VNLib.Plugins.Extensions.Data;
+using VNLib.Plugins.Extensions.Data.Abstractions;
+
+namespace VNLib.Plugins.Essentials.Accounts.Admin.Model
+{
+ internal class User : DbModelBase, IUserEntity
+ {
+ public string? UserId { get; set; }
+ //Users's do not have unique id values
+ [NotMapped]
+ public override string Id
+ {
+ get => UserId!;
+ set => UserId = value;
+ }
+ public override DateTime Created { get; set; }
+ //Do not map the last modified, user table does not have a last modified field.
+ [NotMapped]
+ public override DateTime LastModified { get; set; }
+
+ public ulong Privilages { get; set; }
+ }
+}
diff --git a/VNLib.Plugins.Essentials.Accounts.Admin/Model/UserContext.cs b/VNLib.Plugins.Essentials.Accounts.Admin/Model/UserContext.cs
new file mode 100644
index 0000000..6409b7d
--- /dev/null
+++ b/VNLib.Plugins.Essentials.Accounts.Admin/Model/UserContext.cs
@@ -0,0 +1,17 @@
+
+using Microsoft.EntityFrameworkCore;
+
+using VNLib.Plugins.Extensions.Data;
+
+namespace VNLib.Plugins.Essentials.Accounts.Admin.Model
+{
+ internal class UserContext : TransactionalDbContext
+ {
+ public DbSet<User> Users { get; set; }
+#nullable disable
+ public UserContext(DbContextOptions options):base(options)
+ {
+
+ }
+ }
+}
diff --git a/VNLib.Plugins.Essentials.Accounts.Admin/Model/UserStore.cs b/VNLib.Plugins.Essentials.Accounts.Admin/Model/UserStore.cs
new file mode 100644
index 0000000..b3e5c23
--- /dev/null
+++ b/VNLib.Plugins.Essentials.Accounts.Admin/Model/UserStore.cs
@@ -0,0 +1,48 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using Microsoft.EntityFrameworkCore;
+
+using VNLib.Plugins.Extensions.Data;
+
+namespace VNLib.Plugins.Essentials.Accounts.Admin.Model
+{
+
+ internal class UserStore : DbStore<User>
+ {
+ private readonly DbContextOptions Options;
+
+ public UserStore(DbContextOptions options)
+ {
+ this.Options = options;
+ }
+
+ //Item id's are not used
+ public override string RecordIdBuilder => "";
+
+ protected override IQueryable<User> GetCollectionQueryBuilder(TransactionalDbContext context, params string[] constraints)
+ {
+ return (from user in context.Set<User>()
+ orderby user.Created descending
+ select user);
+ }
+
+ protected override IQueryable<User> GetSingleQueryBuilder(TransactionalDbContext context, params string[] constraints)
+ {
+ string userId = constraints[0];
+ return (from user in context.Set<User>()
+ where user.UserId == userId
+ select user);
+ }
+
+ public override TransactionalDbContext NewContext() => new UserContext(Options);
+
+ protected override void OnRecordUpdate(User newRecord, User currentRecord)
+ {
+ currentRecord.Privilages = currentRecord.Privilages;
+ }
+ }
+}