...
 
Commits (18)
......@@ -26,8 +26,6 @@ bld/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
......@@ -286,3 +284,27 @@ __pycache__/
*.btm.cs
*.odx.cs
*.xsd.cs
# JavaScript Files
**/wwwroot/
**/app/components/**/*.js
**/app/components/**/*.js.map
**/app/directives/**/*.js
**/app/directives/**/*.js.map
**/app/services/**/*.js
**/app/services/**/*.js.map
**/app/domain/**/*.js
**/app/domain/**/*.js.map
**/app/pipes/**/*.js
**/app/pipes/**/*.js.map
**/app/*.js
**/app/*.js.map
!**/app/systemjs.config.js
package-lock.json
.dockerignore
.env
.git
.gitignore
.vs
.vscode
*/bin
*/obj
**/.toolstarget
\ No newline at end of file
namespace MvcCoreTemplate.Data.Common
{
using System;
public interface IDbQueryRunner : IDisposable
{
void RunQuery(string query, params object[] parameters);
}
}
namespace MvcCoreTemplate.Data.Common.Models
{
using System;
public abstract class BaseDeletableModel<TKey> : BaseModel<TKey>, IDeletableEntity
{
public bool IsDeleted { get; set; }
public DateTime? DeletedOn { get; set; }
}
}
namespace MvcCoreTemplate.Data.Common.Models
{
using System;
using System.ComponentModel.DataAnnotations;
public abstract class BaseModel<TKey> : IAuditInfo
{
[Key]
public TKey Id { get; set; }
public DateTime CreatedOn { get; set; }
public DateTime? ModifiedOn { get; set; }
}
}
namespace MvcCoreTemplate.Data.Common.Models
{
using System;
public interface IAuditInfo
{
DateTime CreatedOn { get; set; }
DateTime? ModifiedOn { get; set; }
}
}
namespace MvcCoreTemplate.Data.Common.Models
{
using System;
public interface IDeletableEntity
{
bool IsDeleted { get; set; }
DateTime? DeletedOn { get; set; }
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>..\..\Rules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="..\..\stylecop.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004" PrivateAssets="All" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.4.1" />
</ItemGroup>
</Project>
\ No newline at end of file
namespace MvcCoreTemplate.Data.Common.Repositories
{
using System.Linq;
using System.Threading.Tasks;
using MvcCoreTemplate.Data.Common.Models;
public interface IDeletableEntityRepository<TEntity> : IRepository<TEntity>
where TEntity : class, IDeletableEntity
{
IQueryable<TEntity> AllWithDeleted();
IQueryable<TEntity> AllAsNoTrackingWithDeleted();
Task<TEntity> GetByIdWithDeletedAsync(params object[] id);
void HardDelete(TEntity entity);
void Undelete(TEntity entity);
}
}
namespace MvcCoreTemplate.Data.Common.Repositories
{
using System;
using System.Linq;
using System.Threading.Tasks;
public interface IRepository<TEntity> : IDisposable
where TEntity : class
{
IQueryable<TEntity> All();
IQueryable<TEntity> AllAsNoTracking();
Task<TEntity> GetByIdAsync(params object[] id);
void Add(TEntity entity);
void Update(TEntity entity);
void Delete(TEntity entity);
Task<int> SaveChangesAsync();
}
}
// ReSharper disable VirtualMemberCallInConstructor
namespace MvcCoreTemplate.Data.Models
{
using System;
using MvcCoreTemplate.Data.Common.Models;
using Microsoft.AspNetCore.Identity;
public class ApplicationRole : IdentityRole, IAuditInfo, IDeletableEntity
{
public ApplicationRole()
: this(null)
{
}
public ApplicationRole(string name)
: base(name)
{
this.Id = Guid.NewGuid().ToString();
}
public DateTime CreatedOn { get; set; }
public DateTime? ModifiedOn { get; set; }
public bool IsDeleted { get; set; }
public DateTime? DeletedOn { get; set; }
}
}
// ReSharper disable VirtualMemberCallInConstructor
namespace MvcCoreTemplate.Data.Models
{
using System;
using System.Collections.Generic;
using MvcCoreTemplate.Data.Common.Models;
using Microsoft.AspNetCore.Identity;
public class ApplicationUser : IdentityUser, IAuditInfo, IDeletableEntity
{
public ApplicationUser()
{
this.Id = Guid.NewGuid().ToString();
this.Roles = new HashSet<IdentityUserRole<string>>();
this.Claims = new HashSet<IdentityUserClaim<string>>();
this.Logins = new HashSet<IdentityUserLogin<string>>();
}
// Audit info
public DateTime CreatedOn { get; set; }
public DateTime? ModifiedOn { get; set; }
// Deletable entity
public bool IsDeleted { get; set; }
public DateTime? DeletedOn { get; set; }
public virtual ICollection<IdentityUserRole<string>> Roles { get; set; }
public virtual ICollection<IdentityUserClaim<string>> Claims { get; set; }
public virtual ICollection<IdentityUserLogin<string>> Logins { get; set; }
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>..\..\Rules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="..\..\stylecop.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MvcCoreTemplate.Data.Common\MvcCoreTemplate.Data.Common.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
namespace MvcCoreTemplate.Data
{
using System;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using MvcCoreTemplate.Data.Common.Models;
using MvcCoreTemplate.Data.Models;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
{
private static readonly MethodInfo SetIsDeletedQueryFilterMethod =
typeof(ApplicationDbContext).GetMethod(
nameof(SetIsDeletedQueryFilter),
BindingFlags.NonPublic | BindingFlags.Static);
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public override int SaveChanges() => this.SaveChanges(true);
public override int SaveChanges(bool acceptAllChangesOnSuccess)
{
this.ApplyAuditInfoRules();
return base.SaveChanges(acceptAllChangesOnSuccess);
}
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken)) =>
this.SaveChangesAsync(true, cancellationToken);
public override Task<int> SaveChangesAsync(
bool acceptAllChangesOnSuccess,
CancellationToken cancellationToken = default(CancellationToken))
{
this.ApplyAuditInfoRules();
return base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
}
protected override void OnModelCreating(ModelBuilder builder)
{
// Needed for Identity models configuration
base.OnModelCreating(builder);
ConfigureUserIdentityRelations(builder);
EntityIndexesConfiguration.Configure(builder);
var entityTypes = builder.Model.GetEntityTypes().ToList();
// Set global query filter for not deleted entities only
var deletableEntityTypes = entityTypes
.Where(et => et.ClrType != null && typeof(IDeletableEntity).IsAssignableFrom(et.ClrType));
foreach (var deletableEntityType in deletableEntityTypes)
{
var method = SetIsDeletedQueryFilterMethod.MakeGenericMethod(deletableEntityType.ClrType);
method.Invoke(null, new object[] { builder });
}
// Disable cascade delete
var foreignKeys = entityTypes
.SelectMany(e => e.GetForeignKeys().Where(f => f.DeleteBehavior == DeleteBehavior.Cascade));
foreach (var foreignKey in foreignKeys)
{
foreignKey.DeleteBehavior = DeleteBehavior.Restrict;
}
}
private static void ConfigureUserIdentityRelations(ModelBuilder builder)
{
builder.Entity<ApplicationUser>()
.HasMany(e => e.Claims)
.WithOne()
.HasForeignKey(e => e.UserId)
.IsRequired()
.OnDelete(DeleteBehavior.Restrict);
builder.Entity<ApplicationUser>()
.HasMany(e => e.Logins)
.WithOne()
.HasForeignKey(e => e.UserId)
.IsRequired()
.OnDelete(DeleteBehavior.Restrict);
builder.Entity<ApplicationUser>()
.HasMany(e => e.Roles)
.WithOne()
.HasForeignKey(e => e.UserId)
.IsRequired()
.OnDelete(DeleteBehavior.Restrict);
}
private static void SetIsDeletedQueryFilter<T>(ModelBuilder builder)
where T : class, IDeletableEntity
{
builder.Entity<T>().HasQueryFilter(e => !e.IsDeleted);
}
private void ApplyAuditInfoRules()
{
var changedEntries = this.ChangeTracker
.Entries()
.Where(e =>
e.Entity is IAuditInfo &&
(e.State == EntityState.Added || e.State == EntityState.Modified));
foreach (var entry in changedEntries)
{
var entity = (IAuditInfo)entry.Entity;
if (entry.State == EntityState.Added && entity.CreatedOn == default(DateTime))
{
entity.CreatedOn = DateTime.UtcNow;
}
else
{
entity.ModifiedOn = DateTime.UtcNow;
}
}
}
}
}
namespace MvcCoreTemplate.Data
{
using System.Security.Claims;
using MvcCoreTemplate.Data.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
public class ApplicationRoleStore : RoleStore<
ApplicationRole,
ApplicationDbContext,
string,
IdentityUserRole<string>,
IdentityRoleClaim<string>>
{
public ApplicationRoleStore(ApplicationDbContext context, IdentityErrorDescriber describer = null)
: base(context, describer)
{
}
protected override IdentityRoleClaim<string> CreateRoleClaim(ApplicationRole role, Claim claim) =>
new IdentityRoleClaim<string>
{
RoleId = role.Id,
ClaimType = claim.Type,
ClaimValue = claim.Value
};
}
}
namespace MvcCoreTemplate.Data
{
using System.Security.Claims;
using MvcCoreTemplate.Data.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
public class ApplicationUserStore : UserStore<
ApplicationUser,
ApplicationRole,
ApplicationDbContext,
string,
IdentityUserClaim<string>,
IdentityUserRole<string>,
IdentityUserLogin<string>,
IdentityUserToken<string>,
IdentityRoleClaim<string>>
{
public ApplicationUserStore(ApplicationDbContext context, IdentityErrorDescriber describer = null)
: base(context, describer)
{
}
protected override IdentityUserRole<string> CreateUserRole(ApplicationUser user, ApplicationRole role)
{
return new IdentityUserRole<string> { RoleId = role.Id, UserId = user.Id };
}
protected override IdentityUserClaim<string> CreateUserClaim(ApplicationUser user, Claim claim)
{
var identityUserClaim = new IdentityUserClaim<string> { UserId = user.Id };
identityUserClaim.InitializeFromClaim(claim);
return identityUserClaim;
}
protected override IdentityUserLogin<string> CreateUserLogin(ApplicationUser user, UserLoginInfo login) =>
new IdentityUserLogin<string>
{
UserId = user.Id,
ProviderKey = login.ProviderKey,
LoginProvider = login.LoginProvider,
ProviderDisplayName = login.ProviderDisplayName
};
protected override IdentityUserToken<string> CreateUserToken(
ApplicationUser user,
string loginProvider,
string name,
string value)
{
var token = new IdentityUserToken<string>
{
UserId = user.Id,
LoginProvider = loginProvider,
Name = name,
Value = value
};
return token;
}
}
}
namespace MvcCoreTemplate.Data
{
using System;
using MvcCoreTemplate.Data.Common;
using Microsoft.EntityFrameworkCore;
public class DbQueryRunner : IDbQueryRunner
{
public DbQueryRunner(ApplicationDbContext context)
{
this.Context = context ?? throw new ArgumentNullException(nameof(context));
}
public ApplicationDbContext Context { get; set; }
public void RunQuery(string query, params object[] parameters)
{
this.Context.Database.ExecuteSqlCommand(query, parameters);
}
public void Dispose()
{
this.Context?.Dispose();
}
}
}
namespace MvcCoreTemplate.Data
{
using System.IO;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration;
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
{
public ApplicationDbContext CreateDbContext(string[] args)
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
var connectionString = configuration.GetConnectionString("DefaultConnection");
builder.UseSqlServer(connectionString);
// Stop client query evaluation
builder.ConfigureWarnings(w => w.Throw(RelationalEventId.QueryClientEvaluationWarning));
return new ApplicationDbContext(builder.Options);
}
}
}
namespace MvcCoreTemplate.Data
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Storage;
internal static class EfExpressionHelper
{
private static readonly Type StringType = typeof(string);
private static readonly MethodInfo ValueBufferGetValueMethod =
typeof(ValueBuffer).GetRuntimeProperties().Single(p => p.GetIndexParameters().Any()).GetMethod;
private static readonly MethodInfo EfPropertyMethod =
typeof(EF).GetTypeInfo().GetDeclaredMethod(nameof(Property));
public static Expression<Func<TEntity, bool>> BuildByIdPredicate<TEntity>(
DbContext dbContext,
object[] id)
where TEntity : class
{
if (id == null)
{
throw new ArgumentNullException(nameof(id));
}
var entityType = typeof(TEntity);
var entityParameter = Expression.Parameter(entityType, "e");
var keyProperties = dbContext.Model.FindEntityType(entityType).FindPrimaryKey().Properties;
var predicate = BuildPredicate(keyProperties, new ValueBuffer(id), entityParameter);
return Expression.Lambda<Func<TEntity, bool>>(predicate, entityParameter);
}
private static BinaryExpression BuildPredicate(
IReadOnlyList<IProperty> keyProperties,
ValueBuffer keyValues,
ParameterExpression entityParameter)
{
var keyValuesConstant = Expression.Constant(keyValues);
BinaryExpression predicate = null;
for (var i = 0; i < keyProperties.Count; i++)
{
var property = keyProperties[i];
var equalsExpression =
Expression.Equal(
Expression.Call(
EfPropertyMethod.MakeGenericMethod(property.ClrType),
entityParameter,
Expression.Constant(property.Name, StringType)),
Expression.Convert(
Expression.Call(
keyValuesConstant,
ValueBufferGetValueMethod,
Expression.Constant(i)),
property.ClrType));
predicate = predicate == null ? equalsExpression : Expression.AndAlso(predicate, equalsExpression);
}
return predicate;
}
}
}
namespace MvcCoreTemplate.Data
{
using System.Linq;
using MvcCoreTemplate.Data.Common.Models;
using Microsoft.EntityFrameworkCore;
internal static class EntityIndexesConfiguration
{
public static void Configure(ModelBuilder modelBuilder)
{
// IDeletableEntity.IsDeleted index
var deletableEntityTypes = modelBuilder.Model
.GetEntityTypes()
.Where(et => et.ClrType != null && typeof(IDeletableEntity).IsAssignableFrom(et.ClrType));
foreach (var deletableEntityType in deletableEntityTypes)
{
modelBuilder.Entity(deletableEntityType.ClrType).HasIndex(nameof(IDeletableEntity.IsDeleted));
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace MvcCoreTemplate.Web.Data.Migrations
namespace MvcCoreTemplate.Data.Migrations
{
public partial class CreateIdentitySchema : Migration
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
......@@ -17,6 +15,10 @@ namespace MvcCoreTemplate.Web.Data.Migrations
{
Id = table.Column<string>(nullable: false),
ConcurrencyStamp = table.Column<string>(nullable: true),
CreatedOn = table.Column<DateTime>(nullable: false),
DeletedOn = table.Column<DateTime>(nullable: true),
IsDeleted = table.Column<bool>(nullable: false),
ModifiedOn = table.Column<DateTime>(nullable: true),
Name = table.Column<string>(maxLength: 256, nullable: true),
NormalizedName = table.Column<string>(maxLength: 256, nullable: true)
},
......@@ -25,20 +27,6 @@ namespace MvcCoreTemplate.Web.Data.Migrations
table.PrimaryKey("PK_AspNetRoles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetUserTokens",
columns: table => new
{
UserId = table.Column<string>(nullable: false),
LoginProvider = table.Column<string>(nullable: false),
Name = table.Column<string>(nullable: false),
Value = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
});
migrationBuilder.CreateTable(
name: "AspNetUsers",
columns: table => new
......@@ -46,10 +34,14 @@ namespace MvcCoreTemplate.Web.Data.Migrations
Id = table.Column<string>(nullable: false),
AccessFailedCount = table.Column<int>(nullable: false),
ConcurrencyStamp = table.Column<string>(nullable: true),
CreatedOn = table.Column<DateTime>(nullable: false),
DeletedOn = table.Column<DateTime>(nullable: true),
Email = table.Column<string>(maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(nullable: false),
IsDeleted = table.Column<bool>(nullable: false),
LockoutEnabled = table.Column<bool>(nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(nullable: true),
ModifiedOn = table.Column<DateTime>(nullable: true),
NormalizedEmail = table.Column<string>(maxLength: 256, nullable: true),
NormalizedUserName = table.Column<string>(maxLength: 256, nullable: true),
PasswordHash = table.Column<string>(nullable: true),
......@@ -82,7 +74,7 @@ namespace MvcCoreTemplate.Web.Data.Migrations
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
......@@ -103,7 +95,7 @@ namespace MvcCoreTemplate.Web.Data.Migrations
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
......@@ -123,7 +115,7 @@ namespace MvcCoreTemplate.Web.Data.Migrations
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
......@@ -141,25 +133,77 @@ namespace MvcCoreTemplate.Web.Data.Migrations
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "RoleNameIndex",
table: "AspNetRoles",
column: "NormalizedName");
migrationBuilder.CreateTable(
name: "AspNetUserTokens",
columns: table => new
{
UserId = table.Column<string>(nullable: false),
LoginProvider = table.Column<string>(nullable: false),
Name = table.Column<string>(nullable: false),
Value = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
table.ForeignKey(
name: "FK_AspNetUserTokens_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "TodoItems",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
AuthorId = table.Column<string>(nullable: false),
CreatedOn = table.Column<DateTime>(nullable: false),
DeletedOn = table.Column<DateTime>(nullable: true),
IsDeleted = table.Column<bool>(nullable: false),
IsDone = table.Column<bool>(nullable: false),
ModifiedOn = table.Column<DateTime>(nullable: true),
Title = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TodoItems", x => x.Id);
table.ForeignKey(
name: "FK_TodoItems_AspNetUsers_AuthorId",
column: x => x.AuthorId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_AspNetRoleClaims_RoleId",
table: "AspNetRoleClaims",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "IX_AspNetRoles_IsDeleted",
table: "AspNetRoles",
column: "IsDeleted");
migrationBuilder.CreateIndex(
name: "RoleNameIndex",
table: "AspNetRoles",
column: "NormalizedName",
unique: true,
filter: "[NormalizedName] IS NOT NULL");
migrationBuilder.CreateIndex(
name: "IX_AspNetUserClaims_UserId",
table: "AspNetUserClaims",
......@@ -176,9 +220,9 @@ namespace MvcCoreTemplate.Web.Data.Migrations
column: "RoleId");
migrationBuilder.CreateIndex(
name: "IX_AspNetUserRoles_UserId",
table: "AspNetUserRoles",
column: "UserId");
name: "IX_AspNetUsers_IsDeleted",
table: "AspNetUsers",
column: "IsDeleted");
migrationBuilder.CreateIndex(
name: "EmailIndex",
......@@ -189,7 +233,18 @@ namespace MvcCoreTemplate.Web.Data.Migrations
name: "UserNameIndex",
table: "AspNetUsers",
column: "NormalizedUserName",
unique: true);
unique: true,
filter: "[NormalizedUserName] IS NOT NULL");
migrationBuilder.CreateIndex(
name: "IX_TodoItems_AuthorId",
table: "TodoItems",
column: "AuthorId");
migrationBuilder.CreateIndex(
name: "IX_TodoItems_IsDeleted",
table: "TodoItems",
column: "IsDeleted");
}
protected override void Down(MigrationBuilder migrationBuilder)
......@@ -209,6 +264,9 @@ namespace MvcCoreTemplate.Web.Data.Migrations
migrationBuilder.DropTable(
name: "AspNetUserTokens");
migrationBuilder.DropTable(
name: "TodoItems");
migrationBuilder.DropTable(
name: "AspNetRoles");
......
using System;
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using MvcCoreTemplate.Data;
using System;
namespace MvcCoreTemplate.Data.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20170425144347_InitialMigration")]
partial class InitialMigration
[Migration("20180426151235_RemoveToDoTable")]
partial class RemoveToDoTable
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "1.1.1")
.HasAnnotation("ProductVersion", "2.0.1-rtm-125")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken();
b.Property<string>("Name")
.HasMaxLength(256);
b.Property<string>("NormalizedName")
.HasMaxLength(256);
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasName("RoleNameIndex");
b.ToTable("AspNetRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim<string>", b =>
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
......@@ -59,7 +40,7 @@ namespace MvcCoreTemplate.Data.Migrations
b.ToTable("AspNetRoleClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<string>", b =>
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
......@@ -78,7 +59,7 @@ namespace MvcCoreTemplate.Data.Migrations
b.ToTable("AspNetUserClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<string>", b =>
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider");
......@@ -96,7 +77,7 @@ namespace MvcCoreTemplate.Data.Migrations
b.ToTable("AspNetUserLogins");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<string>", b =>
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId");
......@@ -109,7 +90,7 @@ namespace MvcCoreTemplate.Data.Migrations
b.ToTable("AspNetUserRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<string>", b =>
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId");
......@@ -124,6 +105,40 @@ namespace MvcCoreTemplate.Data.Migrations
b.ToTable("AspNetUserTokens");
});
modelBuilder.Entity("MvcCoreTemplate.Data.Models.ApplicationRole", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken();
b.Property<DateTime>("CreatedOn");
b.Property<DateTime?>("DeletedOn");
b.Property<bool>("IsDeleted");
b.Property<DateTime?>("ModifiedOn");
b.Property<string>("Name")
.HasMaxLength(256);
b.Property<string>("NormalizedName")
.HasMaxLength(256);
b.HasKey("Id");
b.HasIndex("IsDeleted");
b.HasIndex("NormalizedName")
.IsUnique()
.HasName("RoleNameIndex")
.HasFilter("[NormalizedName] IS NOT NULL");
b.ToTable("AspNetRoles");
});
modelBuilder.Entity("MvcCoreTemplate.Data.Models.ApplicationUser", b =>
{
b.Property<string>("Id")
......@@ -134,15 +149,23 @@ namespace MvcCoreTemplate.Data.Migrations
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken();
b.Property<DateTime>("CreatedOn");
b.Property<DateTime?>("DeletedOn");
b.Property<string>("Email")
.HasMaxLength(256);
b.Property<bool>("EmailConfirmed");
b.Property<bool>("IsDeleted");
b.Property<bool>("LockoutEnabled");
b.Property<DateTimeOffset?>("LockoutEnd");
b.Property<DateTime?>("ModifiedOn");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256);
......@@ -164,52 +187,64 @@ namespace MvcCoreTemplate.Data.Migrations
b.HasKey("Id");
b.HasIndex("IsDeleted");
b.HasIndex("NormalizedEmail")
.HasName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasName("UserNameIndex");
.HasName("UserNameIndex")
.HasFilter("[NormalizedUserName] IS NOT NULL");
b.ToTable("AspNetUsers");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim<string>", b =>
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole")
.WithMany("Claims")
b.HasOne("MvcCoreTemplate.Data.Models.ApplicationRole")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade);
.OnDelete(DeleteBehavior.Restrict);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<string>", b =>
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("MvcCoreTemplate.Data.Models.ApplicationUser")
.WithMany("Claims")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
.OnDelete(DeleteBehavior.Restrict);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<string>", b =>
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("MvcCoreTemplate.Data.Models.ApplicationUser")
.WithMany("Logins")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
.OnDelete(DeleteBehavior.Restrict);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<string>", b =>
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole")
.WithMany("Users")
b.HasOne("MvcCoreTemplate.Data.Models.ApplicationRole")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade);
.OnDelete(DeleteBehavior.Restrict);
b.HasOne("MvcCoreTemplate.Data.Models.ApplicationUser")
.WithMany("Roles")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
.OnDelete(DeleteBehavior.Restrict);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("MvcCoreTemplate.Data.Models.ApplicationUser")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict);
});
#pragma warning restore 612, 618
}
}
}
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;
namespace MvcCoreTemplate.Data.Migrations
{
public partial class RemoveToDoTable : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "TodoItems");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "TodoItems",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
AuthorId = table.Column<string>(nullable: false),
CreatedOn = table.Column<DateTime>(nullable: false),
DeletedOn = table.Column<DateTime>(nullable: true),
IsDeleted = table.Column<bool>(nullable: false),
IsDone = table.Column<bool>(nullable: false),
ModifiedOn = table.Column<DateTime>(nullable: true),
Title = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TodoItems", x => x.Id);
table.ForeignKey(
name: "FK_TodoItems_AspNetUsers_AuthorId",
column: x => x.AuthorId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_TodoItems_AuthorId",
table: "TodoItems",
column: "AuthorId");
migrationBuilder.CreateIndex(
name: "IX_TodoItems_IsDeleted",
table: "TodoItems",
column: "IsDeleted");
}
}
}
using System;
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using MvcCoreTemplate.Data;
using System;
namespace MvcCoreTemplate.Data.Migrations
{
......@@ -12,34 +15,12 @@ namespace MvcCoreTemplate.Data.Migrations
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "1.1.1")
.HasAnnotation("ProductVersion", "2.0.1-rtm-125")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken();
b.Property<string>("Name")
.HasMaxLength(256);
b.Property<string>("NormalizedName")
.HasMaxLength(256);
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasName("RoleNameIndex");
b.ToTable("AspNetRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRoleClaim<string>", b =>
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
......@@ -58,7 +39,7 @@ namespace MvcCoreTemplate.Data.Migrations
b.ToTable("AspNetRoleClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<string>", b =>
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
......@@ -77,7 +58,7 @@ namespace MvcCoreTemplate.Data.Migrations
b.ToTable("AspNetUserClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin<string>", b =>
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider");
......@@ -95,7 +76,7 @@ namespace MvcCoreTemplate.Data.Migrations
b.ToTable("AspNetUserLogins");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole<string>", b =>
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId");
......@@ -108,7 +89,7 @@ namespace MvcCoreTemplate.Data.Migrations
b.ToTable("AspNetUserRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserToken<string>", b =>
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId");
......@@ -123,6 +104,40 @@ namespace MvcCoreTemplate.Data.Migrations
b.ToTable("AspNetUserTokens");
});