Archived
Added first app template
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using app.Interface.Repositories;
|
||||
using app.Model;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace app.Data
|
||||
{
|
||||
public class DatabaseContext : DbContext, IUnitOfWork
|
||||
{
|
||||
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options) { }
|
||||
|
||||
public DbSet<AuthUser> AuthUsers { get; set; }
|
||||
|
||||
public Task<int> SaveChangesAsync()
|
||||
{
|
||||
var changedList = ChangeTracker.Entries<IAutoGenerateDateFields>().Where(x => x.State == EntityState.Added || x.State == EntityState.Modified);
|
||||
foreach (var item in changedList)
|
||||
{
|
||||
item.Entity.LastModifiedOn = DateTime.UtcNow;
|
||||
if (item.State == EntityState.Added)
|
||||
item.Entity.CreatedOn = DateTime.UtcNow;
|
||||
}
|
||||
return base.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public override int SaveChanges()
|
||||
{
|
||||
var changedList = ChangeTracker.Entries<IAutoGenerateDateFields>().Where(x => x.State == EntityState.Added || x.State == EntityState.Modified);
|
||||
foreach (var item in changedList)
|
||||
{
|
||||
item.Entity.LastModifiedOn = DateTime.UtcNow;
|
||||
if (item.State == EntityState.Added)
|
||||
item.Entity.CreatedOn = DateTime.UtcNow;
|
||||
}
|
||||
return base.SaveChanges();
|
||||
}
|
||||
|
||||
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
// Datum der letzten Änderung, etc. setzen
|
||||
DateTimeOffset now = DateTimeOffset.UtcNow;
|
||||
var changedList = ChangeTracker.Entries<IAutoGenerateDateFields>().Where(x => x.State == EntityState.Added || x.State == EntityState.Modified);
|
||||
foreach (var item in changedList)
|
||||
{
|
||||
item.Entity.LastModifiedOn = now;
|
||||
if (item.State == EntityState.Added)
|
||||
item.Entity.CreatedOn = now;
|
||||
}
|
||||
return base.SaveChangesAsync();
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<AuthUser>()
|
||||
.HasIndex(au => au.EMail)
|
||||
.IsUnique(true);
|
||||
|
||||
modelBuilder.Entity<AuthUser>()
|
||||
.HasIndex(au => au.ConfirmationId)
|
||||
.IsUnique(true);
|
||||
|
||||
modelBuilder.Entity<AuthUser>()
|
||||
.HasIndex(au => au.ForgotPasswordId)
|
||||
.IsUnique(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace app.Data
|
||||
{
|
||||
public class DesignTimeContextFactory : IDesignTimeDbContextFactory<DatabaseContext>
|
||||
{
|
||||
public DatabaseContext CreateDbContext(string[] args)
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<DatabaseContext>();
|
||||
optionsBuilder.UseMySql(
|
||||
"server=localhost;user=sh_login_counter;password=mZaKBHY1lhzQoCAv;database=sh_login_counter",
|
||||
new MySqlServerVersion(new Version(10, 3, 32))
|
||||
);
|
||||
|
||||
return new DatabaseContext(optionsBuilder.Options);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace app.Data
|
||||
{
|
||||
public static class LinqExtension
|
||||
{
|
||||
public static IQueryable<T> OrderByMember<T>(this IQueryable<T> q, string SortField)
|
||||
{
|
||||
var param = Expression.Parameter(typeof(T), "p");
|
||||
var prop = Expression.Property(param, SortField);
|
||||
var exp = Expression.Lambda(prop, param);
|
||||
Type[] types = new Type[] { q.ElementType, exp.Body.Type };
|
||||
var mce = Expression.Call(typeof(Queryable), "OrderBy", types, q.Expression, exp);
|
||||
return q.Provider.CreateQuery<T>(mce);
|
||||
}
|
||||
|
||||
public static IQueryable<T> OrderByMemberDescending<T>(this IQueryable<T> q, string SortField)
|
||||
{
|
||||
var param = Expression.Parameter(typeof(T), "p");
|
||||
var prop = Expression.Property(param, SortField);
|
||||
var exp = Expression.Lambda(prop, param);
|
||||
Type[] types = new Type[] { q.ElementType, exp.Body.Type };
|
||||
var mce = Expression.Call(typeof(Queryable), "OrderByDescending", types, q.Expression, exp);
|
||||
return q.Provider.CreateQuery<T>(mce);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+291
@@ -0,0 +1,291 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using app.Data;
|
||||
|
||||
namespace app.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(DatabaseContext))]
|
||||
[Migration("20210213133159_2021_03_10")]
|
||||
partial class _2021_03_10
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "3.1.9")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("app.Model.AuthUser", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("ConfirmationId")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("EMail")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<string>("ForgotPasswordId")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<string>("RefreshToken")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTime>("RefreshTokenExpiryTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ConfirmationId")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("EMail")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("ForgotPasswordId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("AuthUsers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Domain", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<bool>("NotifyWhenLogin")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Domains");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Host", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long?>("DomainId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<byte[]>("IPAddress")
|
||||
.HasColumnType("varbinary(1400)")
|
||||
.HasMaxLength(1400);
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<bool>("NotifyWhenLogin")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<long>("OSId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DomainId");
|
||||
|
||||
b.HasIndex("OSId");
|
||||
|
||||
b.HasIndex("DomainId", "Name")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("IPAddress", "Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Hosts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Login", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long>("HostId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTimeOffset>("Time")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long>("UserId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("HostId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Logins");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.OperatingSystem", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("OperatingSystems");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.User", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Discriminator")
|
||||
.IsRequired()
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<bool>("NotifyWhenLogin")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Discriminator", "Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Users");
|
||||
|
||||
b.HasDiscriminator<string>("Discriminator").HasValue("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.DomainUser", b =>
|
||||
{
|
||||
b.HasBaseType("app.Model.User");
|
||||
|
||||
b.Property<long?>("DomainId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasIndex("DomainId");
|
||||
|
||||
b.HasDiscriminator().HasValue("DomainUser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.HostUser", b =>
|
||||
{
|
||||
b.HasBaseType("app.Model.User");
|
||||
|
||||
b.Property<long?>("HostId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasIndex("HostId");
|
||||
|
||||
b.HasDiscriminator().HasValue("HostUser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Host", b =>
|
||||
{
|
||||
b.HasOne("app.Model.Domain", "Domain")
|
||||
.WithMany("Hosts")
|
||||
.HasForeignKey("DomainId");
|
||||
|
||||
b.HasOne("app.Model.OperatingSystem", "OS")
|
||||
.WithMany()
|
||||
.HasForeignKey("OSId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Login", b =>
|
||||
{
|
||||
b.HasOne("app.Model.Host", "Host")
|
||||
.WithMany("Logins")
|
||||
.HasForeignKey("HostId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("app.Model.User", "User")
|
||||
.WithMany("Logins")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.DomainUser", b =>
|
||||
{
|
||||
b.HasOne("app.Model.Domain", "Domain")
|
||||
.WithMany("Users")
|
||||
.HasForeignKey("DomainId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.HostUser", b =>
|
||||
{
|
||||
b.HasOne("app.Model.Host", "Host")
|
||||
.WithMany("Users")
|
||||
.HasForeignKey("HostId");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace app.Data.Migrations
|
||||
{
|
||||
public partial class _2021_03_10 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AuthUsers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
FirstName = table.Column<string>(nullable: true),
|
||||
LastName = table.Column<string>(nullable: true),
|
||||
EMail = table.Column<string>(nullable: true),
|
||||
Password = table.Column<string>(nullable: true),
|
||||
RefreshToken = table.Column<string>(nullable: true),
|
||||
ConfirmationId = table.Column<string>(nullable: true),
|
||||
ForgotPasswordId = table.Column<string>(nullable: true),
|
||||
RefreshTokenExpiryTime = table.Column<DateTime>(nullable: false),
|
||||
CreatedOn = table.Column<DateTimeOffset>(nullable: false),
|
||||
LastModifiedOn = table.Column<DateTimeOffset>(nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AuthUsers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Domains",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
Name = table.Column<string>(nullable: true),
|
||||
NotifyWhenLogin = table.Column<bool>(nullable: false),
|
||||
CreatedOn = table.Column<DateTimeOffset>(nullable: false),
|
||||
LastModifiedOn = table.Column<DateTimeOffset>(nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Domains", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "OperatingSystems",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
Name = table.Column<string>(nullable: true),
|
||||
CreatedOn = table.Column<DateTimeOffset>(nullable: false),
|
||||
LastModifiedOn = table.Column<DateTimeOffset>(nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_OperatingSystems", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Hosts",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
Name = table.Column<string>(nullable: true),
|
||||
IPAddress = table.Column<byte[]>(maxLength: 1400, nullable: true),
|
||||
NotifyWhenLogin = table.Column<bool>(nullable: false),
|
||||
DomainId = table.Column<long>(nullable: true),
|
||||
OSId = table.Column<long>(nullable: false),
|
||||
CreatedOn = table.Column<DateTimeOffset>(nullable: false),
|
||||
LastModifiedOn = table.Column<DateTimeOffset>(nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Hosts", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Hosts_Domains_DomainId",
|
||||
column: x => x.DomainId,
|
||||
principalTable: "Domains",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_Hosts_OperatingSystems_OSId",
|
||||
column: x => x.OSId,
|
||||
principalTable: "OperatingSystems",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Users",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
Name = table.Column<string>(nullable: true),
|
||||
NotifyWhenLogin = table.Column<bool>(nullable: false),
|
||||
CreatedOn = table.Column<DateTimeOffset>(nullable: false),
|
||||
LastModifiedOn = table.Column<DateTimeOffset>(nullable: false),
|
||||
Discriminator = table.Column<string>(nullable: false),
|
||||
DomainId = table.Column<long>(nullable: true),
|
||||
HostId = table.Column<long>(nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Users", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Users_Domains_DomainId",
|
||||
column: x => x.DomainId,
|
||||
principalTable: "Domains",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_Users_Hosts_HostId",
|
||||
column: x => x.HostId,
|
||||
principalTable: "Hosts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Logins",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
Time = table.Column<DateTimeOffset>(nullable: false),
|
||||
HostId = table.Column<long>(nullable: false),
|
||||
UserId = table.Column<long>(nullable: false),
|
||||
CreatedOn = table.Column<DateTimeOffset>(nullable: false),
|
||||
LastModifiedOn = table.Column<DateTimeOffset>(nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Logins", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Logins_Hosts_HostId",
|
||||
column: x => x.HostId,
|
||||
principalTable: "Hosts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_Logins_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AuthUsers_ConfirmationId",
|
||||
table: "AuthUsers",
|
||||
column: "ConfirmationId",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AuthUsers_EMail",
|
||||
table: "AuthUsers",
|
||||
column: "EMail",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AuthUsers_ForgotPasswordId",
|
||||
table: "AuthUsers",
|
||||
column: "ForgotPasswordId",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Hosts_DomainId",
|
||||
table: "Hosts",
|
||||
column: "DomainId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Hosts_OSId",
|
||||
table: "Hosts",
|
||||
column: "OSId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Hosts_DomainId_Name",
|
||||
table: "Hosts",
|
||||
columns: new[] { "DomainId", "Name" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Hosts_IPAddress_Name",
|
||||
table: "Hosts",
|
||||
columns: new[] { "IPAddress", "Name" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Logins_HostId",
|
||||
table: "Logins",
|
||||
column: "HostId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Logins_UserId",
|
||||
table: "Logins",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_OperatingSystems_Name",
|
||||
table: "OperatingSystems",
|
||||
column: "Name",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Users_DomainId",
|
||||
table: "Users",
|
||||
column: "DomainId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Users_HostId",
|
||||
table: "Users",
|
||||
column: "HostId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Users_Discriminator_Name",
|
||||
table: "Users",
|
||||
columns: new[] { "Discriminator", "Name" },
|
||||
unique: true);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "AuthUsers");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Logins");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Users");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Hosts");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Domains");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "OperatingSystems");
|
||||
}
|
||||
}
|
||||
}
|
||||
+294
@@ -0,0 +1,294 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using app.Data;
|
||||
|
||||
namespace app.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(DatabaseContext))]
|
||||
[Migration("20210217201310_2021_03_13")]
|
||||
partial class _2021_03_13
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "3.1.9")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("app.Model.AuthUser", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<int>("AuthRole")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ConfirmationId")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("EMail")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<string>("ForgotPasswordId")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<string>("RefreshToken")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTime>("RefreshTokenExpiryTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ConfirmationId")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("EMail")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("ForgotPasswordId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("AuthUsers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Domain", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<bool>("NotifyWhenLogin")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Domains");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Host", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long?>("DomainId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<byte[]>("IPAddress")
|
||||
.HasColumnType("varbinary(1400)")
|
||||
.HasMaxLength(1400);
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<bool>("NotifyWhenLogin")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<long>("OSId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DomainId");
|
||||
|
||||
b.HasIndex("OSId");
|
||||
|
||||
b.HasIndex("DomainId", "Name")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("IPAddress", "Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Hosts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Login", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long>("HostId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTimeOffset>("Time")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long>("UserId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("HostId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Logins");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.OperatingSystem", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("OperatingSystems");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.User", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Discriminator")
|
||||
.IsRequired()
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<bool>("NotifyWhenLogin")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Discriminator", "Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Users");
|
||||
|
||||
b.HasDiscriminator<string>("Discriminator").HasValue("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.DomainUser", b =>
|
||||
{
|
||||
b.HasBaseType("app.Model.User");
|
||||
|
||||
b.Property<long?>("DomainId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasIndex("DomainId");
|
||||
|
||||
b.HasDiscriminator().HasValue("DomainUser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.HostUser", b =>
|
||||
{
|
||||
b.HasBaseType("app.Model.User");
|
||||
|
||||
b.Property<long?>("HostId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasIndex("HostId");
|
||||
|
||||
b.HasDiscriminator().HasValue("HostUser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Host", b =>
|
||||
{
|
||||
b.HasOne("app.Model.Domain", "Domain")
|
||||
.WithMany("Hosts")
|
||||
.HasForeignKey("DomainId");
|
||||
|
||||
b.HasOne("app.Model.OperatingSystem", "OS")
|
||||
.WithMany()
|
||||
.HasForeignKey("OSId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Login", b =>
|
||||
{
|
||||
b.HasOne("app.Model.Host", "Host")
|
||||
.WithMany("Logins")
|
||||
.HasForeignKey("HostId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("app.Model.User", "User")
|
||||
.WithMany("Logins")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.DomainUser", b =>
|
||||
{
|
||||
b.HasOne("app.Model.Domain", "Domain")
|
||||
.WithMany("Users")
|
||||
.HasForeignKey("DomainId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.HostUser", b =>
|
||||
{
|
||||
b.HasOne("app.Model.Host", "Host")
|
||||
.WithMany("Users")
|
||||
.HasForeignKey("HostId");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace app.Data.Migrations
|
||||
{
|
||||
public partial class _2021_03_13 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "AuthRole",
|
||||
table: "AuthUsers",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "AuthRole",
|
||||
table: "AuthUsers");
|
||||
}
|
||||
}
|
||||
}
|
||||
+291
@@ -0,0 +1,291 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using app.Data;
|
||||
|
||||
namespace app.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(DatabaseContext))]
|
||||
[Migration("20210220140309_2021_03_14")]
|
||||
partial class _2021_03_14
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "3.1.9")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("app.Model.AuthUser", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<int>("AuthRole")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ConfirmationId")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("EMail")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<string>("ForgotPasswordId")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<string>("RefreshToken")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTime>("RefreshTokenExpiryTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ConfirmationId")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("EMail")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("ForgotPasswordId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("AuthUsers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Domain", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<bool>("NotifyWhenLogin")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Domains");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Host", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long?>("DomainId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<byte[]>("IPAddress")
|
||||
.HasColumnType("varbinary(1400)")
|
||||
.HasMaxLength(1400);
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<bool>("NotifyWhenLogin")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<long>("OSId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DomainId");
|
||||
|
||||
b.HasIndex("OSId");
|
||||
|
||||
b.HasIndex("DomainId", "Name")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("IPAddress", "Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Hosts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Login", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long>("HostId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTimeOffset>("Time")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long>("UserId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("HostId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Logins");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.OperatingSystem", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("OperatingSystems");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.User", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Discriminator")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<bool>("NotifyWhenLogin")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
|
||||
b.HasDiscriminator<string>("Discriminator").HasValue("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.DomainUser", b =>
|
||||
{
|
||||
b.HasBaseType("app.Model.User");
|
||||
|
||||
b.Property<long?>("DomainId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasIndex("DomainId");
|
||||
|
||||
b.HasDiscriminator().HasValue("DomainUser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.HostUser", b =>
|
||||
{
|
||||
b.HasBaseType("app.Model.User");
|
||||
|
||||
b.Property<long?>("HostId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasIndex("HostId");
|
||||
|
||||
b.HasDiscriminator().HasValue("HostUser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Host", b =>
|
||||
{
|
||||
b.HasOne("app.Model.Domain", "Domain")
|
||||
.WithMany("Hosts")
|
||||
.HasForeignKey("DomainId");
|
||||
|
||||
b.HasOne("app.Model.OperatingSystem", "OS")
|
||||
.WithMany()
|
||||
.HasForeignKey("OSId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Login", b =>
|
||||
{
|
||||
b.HasOne("app.Model.Host", "Host")
|
||||
.WithMany("Logins")
|
||||
.HasForeignKey("HostId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("app.Model.User", "User")
|
||||
.WithMany("Logins")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.DomainUser", b =>
|
||||
{
|
||||
b.HasOne("app.Model.Domain", "Domain")
|
||||
.WithMany("Users")
|
||||
.HasForeignKey("DomainId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.HostUser", b =>
|
||||
{
|
||||
b.HasOne("app.Model.Host", "Host")
|
||||
.WithMany("Users")
|
||||
.HasForeignKey("HostId");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace app.Data.Migrations
|
||||
{
|
||||
public partial class _2021_03_14 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Users_Discriminator_Name",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Name",
|
||||
table: "Users",
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "varchar(255) CHARACTER SET utf8mb4",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Discriminator",
|
||||
table: "Users",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "varchar(255) CHARACTER SET utf8mb4");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Name",
|
||||
table: "Users",
|
||||
type: "varchar(255) CHARACTER SET utf8mb4",
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Discriminator",
|
||||
table: "Users",
|
||||
type: "varchar(255) CHARACTER SET utf8mb4",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string));
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Users_Discriminator_Name",
|
||||
table: "Users",
|
||||
columns: new[] { "Discriminator", "Name" },
|
||||
unique: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using app.Data;
|
||||
|
||||
namespace app.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(DatabaseContext))]
|
||||
partial class DatabaseContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "3.1.9")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("app.Model.AuthUser", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<int>("AuthRole")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ConfirmationId")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("EMail")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<string>("ForgotPasswordId")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<string>("RefreshToken")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTime>("RefreshTokenExpiryTime")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ConfirmationId")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("EMail")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("ForgotPasswordId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("AuthUsers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Domain", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<bool>("NotifyWhenLogin")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Domains");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Host", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long?>("DomainId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<byte[]>("IPAddress")
|
||||
.HasColumnType("varbinary(1400)")
|
||||
.HasMaxLength(1400);
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<bool>("NotifyWhenLogin")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<long>("OSId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DomainId");
|
||||
|
||||
b.HasIndex("OSId");
|
||||
|
||||
b.HasIndex("DomainId", "Name")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("IPAddress", "Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Hosts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Login", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long>("HostId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTimeOffset>("Time")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<long>("UserId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("HostId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Logins");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.OperatingSystem", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("OperatingSystems");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.User", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Discriminator")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<DateTimeOffset>("LastModifiedOn")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||
|
||||
b.Property<bool>("NotifyWhenLogin")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
|
||||
b.HasDiscriminator<string>("Discriminator").HasValue("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.DomainUser", b =>
|
||||
{
|
||||
b.HasBaseType("app.Model.User");
|
||||
|
||||
b.Property<long?>("DomainId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasIndex("DomainId");
|
||||
|
||||
b.HasDiscriminator().HasValue("DomainUser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.HostUser", b =>
|
||||
{
|
||||
b.HasBaseType("app.Model.User");
|
||||
|
||||
b.Property<long?>("HostId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasIndex("HostId");
|
||||
|
||||
b.HasDiscriminator().HasValue("HostUser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Host", b =>
|
||||
{
|
||||
b.HasOne("app.Model.Domain", "Domain")
|
||||
.WithMany("Hosts")
|
||||
.HasForeignKey("DomainId");
|
||||
|
||||
b.HasOne("app.Model.OperatingSystem", "OS")
|
||||
.WithMany()
|
||||
.HasForeignKey("OSId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.Login", b =>
|
||||
{
|
||||
b.HasOne("app.Model.Host", "Host")
|
||||
.WithMany("Logins")
|
||||
.HasForeignKey("HostId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("app.Model.User", "User")
|
||||
.WithMany("Logins")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.DomainUser", b =>
|
||||
{
|
||||
b.HasOne("app.Model.Domain", "Domain")
|
||||
.WithMany("Users")
|
||||
.HasForeignKey("DomainId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("app.Model.HostUser", b =>
|
||||
{
|
||||
b.HasOne("app.Model.Host", "Host")
|
||||
.WithMany("Users")
|
||||
.HasForeignKey("HostId");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using app.Interface.Repositories;
|
||||
using app.Model;
|
||||
using app.Share.Common;
|
||||
|
||||
namespace app.Data.Repositories
|
||||
{
|
||||
public class AuthUserRepositoryImpl : IAuthUserRepository
|
||||
{
|
||||
private readonly DatabaseContext _databaseContext;
|
||||
|
||||
private DbSet<AuthUser> _authUsers { get { return _databaseContext.AuthUsers; } }
|
||||
|
||||
public AuthUserRepositoryImpl(DatabaseContext databaseContext)
|
||||
{
|
||||
_databaseContext = databaseContext;
|
||||
}
|
||||
|
||||
public async Task<List<AuthUser>> GetAllAuthUsersAsync()
|
||||
{
|
||||
return await _authUsers
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<(List<AuthUser>, int totalCount)> GetFilteredAuthUsersAsync(AuthUserSelectCriterion selectCriterion)
|
||||
{
|
||||
var query = _authUsers
|
||||
.Select(u => new AuthUser
|
||||
{
|
||||
Id = u.Id,
|
||||
FirstName = u.FirstName,
|
||||
LastName = u.LastName,
|
||||
EMail = u.EMail,
|
||||
ConfirmationId = u.ConfirmationId,
|
||||
AuthRole = u.AuthRole
|
||||
});
|
||||
|
||||
// FirstName filter
|
||||
if (!string.IsNullOrWhiteSpace(selectCriterion.FirstName))
|
||||
query = query.Where(u => u.FirstName.Contains(selectCriterion.FirstName) || u.FirstName == selectCriterion.FirstName);
|
||||
|
||||
// LastName filter
|
||||
if (!string.IsNullOrWhiteSpace(selectCriterion.LastName))
|
||||
query = query.Where(u => u.LastName.Contains(selectCriterion.LastName) || u.LastName == selectCriterion.LastName);
|
||||
|
||||
// EMail filter
|
||||
if (!string.IsNullOrWhiteSpace(selectCriterion.EMail))
|
||||
query = query.Where(u => u.EMail.Contains(selectCriterion.EMail) || u.EMail == selectCriterion.EMail);
|
||||
|
||||
// AuthRole filter
|
||||
if (selectCriterion.AuthRole != null)
|
||||
query = query.Where(u => u.AuthRole == (AuthRoles)selectCriterion.AuthRole);
|
||||
|
||||
// sort
|
||||
if (!string.IsNullOrWhiteSpace(selectCriterion.SortColumn) && !string.IsNullOrWhiteSpace(selectCriterion.SortDirection))
|
||||
{
|
||||
var critSortDirection = selectCriterion.SortDirection?.ToLower();
|
||||
if (critSortDirection == "desc" || critSortDirection == "descending")
|
||||
query = query.OrderByMemberDescending(selectCriterion.SortColumn);
|
||||
else
|
||||
query = query.OrderByMember(selectCriterion.SortColumn);
|
||||
}
|
||||
|
||||
var skip = selectCriterion.PageSize * selectCriterion.PageIndex;
|
||||
if (skip < 0)
|
||||
skip = 0;
|
||||
|
||||
var totalCount = await query.CountAsync();
|
||||
|
||||
var list = await query.Skip(skip).Take(selectCriterion.PageSize).AsNoTracking().ToListAsync();
|
||||
|
||||
return (list, totalCount);
|
||||
}
|
||||
|
||||
public async Task<AuthUser> GetAuthUserByEMailAsync(string email)
|
||||
{
|
||||
return await _authUsers
|
||||
.Where(au => au.EMail == email)
|
||||
.FirstAsync();
|
||||
}
|
||||
|
||||
public async Task<AuthUser> FindAuthUserByEMailAsync(string email)
|
||||
{
|
||||
return await _authUsers
|
||||
.Where(au => au.EMail == email)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<AuthUser> FindAuthUserByEMailConfirmationIdAsync(string id)
|
||||
{
|
||||
return await _authUsers
|
||||
.Where(au => au.ConfirmationId == id)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<AuthUser> FindAuthUserByEMailForgotPasswordIdAsync(string id)
|
||||
{
|
||||
return await _authUsers
|
||||
.Where(au => au.ForgotPasswordId == id)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public void AddAuthUser(AuthUser user)
|
||||
{
|
||||
_authUsers.Add(user);
|
||||
}
|
||||
|
||||
public async Task DeleteAuthUserByEMailAsync(string email)
|
||||
{
|
||||
var au = await _authUsers
|
||||
.Where(au => au.EMail == email)
|
||||
.FirstAsync();
|
||||
|
||||
_authUsers.Remove(au);
|
||||
}
|
||||
|
||||
public void DeleteAuthUser(AuthUser user)
|
||||
{
|
||||
_authUsers.Remove(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.2"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NLog" Version="4.7.13"/>
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.1"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\app.Model\app.Model.csproj"/>
|
||||
<ProjectReference Include="..\app.Interface\app.Interface.csproj"/>
|
||||
<ProjectReference Include="..\app.Share.Common\app.Share.Common.csproj"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user