From 526c2364b9ad685d1c000fc8a168bf1305aaa8b7 Mon Sep 17 00:00:00 2001 From: vman Date: Fri, 18 Nov 2022 16:08:51 -0500 Subject: Add project files. --- .../Model/User.cs | 26 ++++++++++++ .../Model/UserContext.cs | 17 ++++++++ .../Model/UserStore.cs | 48 ++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 VNLib.Plugins.Essentials.Accounts.Admin/Model/User.cs create mode 100644 VNLib.Plugins.Essentials.Accounts.Admin/Model/UserContext.cs create mode 100644 VNLib.Plugins.Essentials.Accounts.Admin/Model/UserStore.cs (limited to 'VNLib.Plugins.Essentials.Accounts.Admin/Model') 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 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 + { + private readonly DbContextOptions Options; + + public UserStore(DbContextOptions options) + { + this.Options = options; + } + + //Item id's are not used + public override string RecordIdBuilder => ""; + + protected override IQueryable GetCollectionQueryBuilder(TransactionalDbContext context, params string[] constraints) + { + return (from user in context.Set() + orderby user.Created descending + select user); + } + + protected override IQueryable GetSingleQueryBuilder(TransactionalDbContext context, params string[] constraints) + { + string userId = constraints[0]; + return (from user in context.Set() + 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; + } + } +} -- cgit