diff --git a/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/Account/Manage/Index.cshtml b/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/Account/Manage/Index.cshtml
new file mode 100644
index 0000000..02ae1b5
--- /dev/null
+++ b/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/Account/Manage/Index.cshtml
@@ -0,0 +1,50 @@
+@page
+@model IndexModel
+@{
+ ViewData["Title"] = "Profile";
+}
+
+
@ViewData["Title"]
+@await Html.PartialAsync("_StatusMessage", Model.StatusMessage)
+
+
+@section Scripts {
+
+}
diff --git a/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/Account/Manage/Index.cshtml.cs b/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/Account/Manage/Index.cshtml.cs
new file mode 100644
index 0000000..9e0d2e0
--- /dev/null
+++ b/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/Account/Manage/Index.cshtml.cs
@@ -0,0 +1,168 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text.Encodings.Web;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Identity.UI.Services;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using ToDoApp.Models;
+
+namespace ToDoApp.Areas.Identity.Pages.Account.Manage
+{
+ public partial class IndexModel : PageModel
+ {
+ private readonly UserManager _userManager;
+ private readonly SignInManager _signInManager;
+ private readonly IEmailSender _emailSender;
+
+ public IndexModel(
+ UserManager userManager,
+ SignInManager signInManager,
+ IEmailSender emailSender)
+ {
+ _userManager = userManager;
+ _signInManager = signInManager;
+ _emailSender = emailSender;
+ }
+
+ public string Username { get; set; }
+
+ public bool IsEmailConfirmed { get; set; }
+
+ [TempData]
+ public string StatusMessage { get; set; }
+
+ [BindProperty]
+ public InputModel Input { get; set; }
+
+ public class InputModel
+ {
+ [Required]
+ [EmailAddress]
+ public string Email { get; set; }
+
+ [Phone]
+ [Display(Name = "Phone number")]
+ public string PhoneNumber { get; set; }
+
+ [DisplayFormat(DataFormatString = "MM/dd/yyyy", ConvertEmptyStringToNull = true)]
+ [Display(Name = "Date of Birth")]
+ [DataType(DataType.Date)]
+ public DateTime? DateOfBirth { get; set; }
+ }
+
+ public async Task OnGetAsync()
+ {
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ var userName = await _userManager.GetUserNameAsync(user);
+ var email = await _userManager.GetEmailAsync(user);
+ var phoneNumber = await _userManager.GetPhoneNumberAsync(user);
+ var dateOfBirth = user.DateOfBirth;
+
+ Username = userName;
+
+ Input = new InputModel
+ {
+ Email = email,
+ PhoneNumber = phoneNumber,
+ DateOfBirth = dateOfBirth
+ };
+
+ IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user);
+
+ return Page();
+ }
+
+ public async Task OnPostAsync()
+ {
+ if (!ModelState.IsValid)
+ {
+ return Page();
+ }
+
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+ var email = await _userManager.GetEmailAsync(user);
+ if (Input.Email != email)
+ {
+ var setEmailResult = await _userManager.SetEmailAsync(user, Input.Email);
+ if (!setEmailResult.Succeeded)
+ {
+ var userId = await _userManager.GetUserIdAsync(user);
+ throw new InvalidOperationException($"Unexpected error occurred setting email for user with ID '{userId}'.");
+ }
+ }
+
+ var phoneNumber = await _userManager.GetPhoneNumberAsync(user);
+ if (Input.PhoneNumber != phoneNumber)
+ {
+ var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, Input.PhoneNumber);
+ if (!setPhoneResult.Succeeded)
+ {
+ var userId = await _userManager.GetUserIdAsync(user);
+ throw new InvalidOperationException($"Unexpected error occurred setting phone number for user with ID '{userId}'.");
+ }
+ }
+
+ var dateOfBirth = user.DateOfBirth;
+ if (Input.DateOfBirth != dateOfBirth)
+ {
+ var latestUser = await _userManager.GetUserAsync(User);
+ latestUser.DateOfBirth = Input.DateOfBirth;
+ var setDateOfBirthResult = await _userManager.UpdateAsync(latestUser);
+ if (!setDateOfBirthResult.Succeeded)
+ {
+ var userId = await _userManager.GetUserIdAsync(user);
+ throw new InvalidOperationException($"Unexpected error occurred setting date of birth for user with ID '{userId}'.");
+ }
+ }
+
+ await _signInManager.RefreshSignInAsync(user);
+ StatusMessage = "Your profile has been updated";
+ return RedirectToPage();
+ }
+
+ public async Task OnPostSendVerificationEmailAsync()
+ {
+ if (!ModelState.IsValid)
+ {
+ return Page();
+ }
+
+ var user = await _userManager.GetUserAsync(User);
+ if (user == null)
+ {
+ return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
+ }
+
+
+ var userId = await _userManager.GetUserIdAsync(user);
+ var email = await _userManager.GetEmailAsync(user);
+ var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
+ var callbackUrl = Url.Page(
+ "/Account/ConfirmEmail",
+ pageHandler: null,
+ values: new { userId = userId, code = code },
+ protocol: Request.Scheme);
+ await _emailSender.SendEmailAsync(
+ email,
+ "Confirm your email",
+ $"Please confirm your account by clicking here.");
+
+ StatusMessage = "Verification email sent. Please check your email.";
+ return RedirectToPage();
+ }
+ }
+}
diff --git a/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/Account/Manage/_ViewImports.cshtml b/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/Account/Manage/_ViewImports.cshtml
new file mode 100644
index 0000000..e34e128
--- /dev/null
+++ b/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/Account/Manage/_ViewImports.cshtml
@@ -0,0 +1 @@
+@using ToDoApp.Areas.Identity.Pages.Account.Manage
diff --git a/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/Account/_ViewImports.cshtml b/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/Account/_ViewImports.cshtml
new file mode 100644
index 0000000..3366e64
--- /dev/null
+++ b/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/Account/_ViewImports.cshtml
@@ -0,0 +1 @@
+@using ToDoApp.Areas.Identity.Pages.Account
\ No newline at end of file
diff --git a/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/_ValidationScriptsPartial.cshtml b/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/_ValidationScriptsPartial.cshtml
new file mode 100644
index 0000000..bacc0ae
--- /dev/null
+++ b/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/_ValidationScriptsPartial.cshtml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
diff --git a/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/_ViewImports.cshtml b/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/_ViewImports.cshtml
new file mode 100644
index 0000000..8d9e90c
--- /dev/null
+++ b/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/_ViewImports.cshtml
@@ -0,0 +1,5 @@
+@using Microsoft.AspNetCore.Identity
+@using ToDoApp.Areas.Identity
+@using Microsoft.AspNetCore.Identity
+@namespace ToDoApp.Areas.Identity.Pages
+@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
diff --git a/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/_ViewStart.cshtml b/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/_ViewStart.cshtml
new file mode 100644
index 0000000..94fd419
--- /dev/null
+++ b/Lesson06/StartOfLesson/ToDo/Areas/Identity/Pages/_ViewStart.cshtml
@@ -0,0 +1,4 @@
+
+@{
+ Layout = "/Views/Shared/_Layout.cshtml";
+}
diff --git a/Lesson06/StartOfLesson/ToDo/Controllers/HomeController.cs b/Lesson06/StartOfLesson/ToDo/Controllers/HomeController.cs
index 8c5e1b7..2377b48 100644
--- a/Lesson06/StartOfLesson/ToDo/Controllers/HomeController.cs
+++ b/Lesson06/StartOfLesson/ToDo/Controllers/HomeController.cs
@@ -3,13 +3,16 @@
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
+using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ToDoApp.Models;
namespace ToDoApp.Controllers
{
+ [Authorize(Roles = "Admin")]
public class HomeController : Controller
{
+ [AllowAnonymous]
public IActionResult Index()
{
return View();
diff --git a/Lesson06/StartOfLesson/ToDo/Controllers/StatusController.cs b/Lesson06/StartOfLesson/ToDo/Controllers/StatusController.cs
index 6fa4343..b2ffff2 100644
--- a/Lesson06/StartOfLesson/ToDo/Controllers/StatusController.cs
+++ b/Lesson06/StartOfLesson/ToDo/Controllers/StatusController.cs
@@ -1,4 +1,5 @@
using System;
+using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using ToDoApp.Models;
@@ -6,6 +7,7 @@
namespace ToDoApp.Controllers
{
+ [Authorize]
public class StatusController : Controller
{
private readonly IRepository _repository;
@@ -30,6 +32,7 @@ public ActionResult Details(int id)
}
// GET: Status/Create
+ [Authorize(Roles = "Admin")]
public ActionResult Create()
{
return View();
@@ -38,6 +41,7 @@ public ActionResult Create()
// POST: Status/Create
[HttpPost]
[ValidateAntiForgeryToken]
+ [Authorize(Roles = "Admin")]
public ActionResult Create(Status status)
{
try
@@ -52,6 +56,7 @@ public ActionResult Create(Status status)
}
// GET: Status/Edit/5
+ [Authorize(Roles = "Admin")]
public ActionResult Edit(int id)
{
return View(_repository.GetStatus(id));
@@ -60,6 +65,7 @@ public ActionResult Edit(int id)
// POST: Status/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
+ [Authorize(Roles = "Admin")]
public ActionResult Edit(int id, Status status)
{
try
@@ -74,6 +80,7 @@ public ActionResult Edit(int id, Status status)
}
// GET: Status/Delete/5
+ [Authorize(Roles = "Admin")]
public ActionResult Delete(int id)
{
return View(_repository.GetStatus(id));
@@ -82,6 +89,7 @@ public ActionResult Delete(int id)
// POST: Status/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
+ [Authorize(Roles = "Admin")]
public ActionResult Delete(int id, Status status)
{
try
diff --git a/Lesson06/StartOfLesson/ToDo/Controllers/ToDoController.cs b/Lesson06/StartOfLesson/ToDo/Controllers/ToDoController.cs
index 4ccce14..07d48e6 100644
--- a/Lesson06/StartOfLesson/ToDo/Controllers/ToDoController.cs
+++ b/Lesson06/StartOfLesson/ToDo/Controllers/ToDoController.cs
@@ -1,20 +1,26 @@
using System;
+using System.Linq;
+using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
+using ToDoApp.Areas.Tags.Data;
using ToDoApp.Models;
using ToDoApp.Services;
namespace ToDoApp.Controllers
{
+ [Authorize]
public class ToDoController : Controller
{
private readonly IRepository _repository;
+ private readonly TagContext tagContext;
private readonly ILogger _logger;
- public ToDoController(IRepository repository, ILogger logger)
+ public ToDoController(IRepository repository, TagContext tagContext, ILogger logger)
{
_repository = repository;
+ this.tagContext = tagContext;
_logger = logger;
}
@@ -43,6 +49,7 @@ public ActionResult Create(ToDo toDo)
{
try
{
+ toDo.Tags = tagContext.Tags.ToList();
_repository.Add(toDo);
return RedirectToAction(nameof(Index));
}
diff --git a/Lesson06/StartOfLesson/ToDo/Data/ToDoContext.cs b/Lesson06/StartOfLesson/ToDo/Data/ToDoContext.cs
index c427c2b..7815080 100644
--- a/Lesson06/StartOfLesson/ToDo/Data/ToDoContext.cs
+++ b/Lesson06/StartOfLesson/ToDo/Data/ToDoContext.cs
@@ -3,12 +3,14 @@
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using ToDoApp.Models;
namespace ToDoApp.Data
{
- public class ToDoContext : DbContext, IReadOnlyToDoContext
+ public class ToDoContext : IdentityDbContext, int>, IReadOnlyToDoContext
{
public ToDoContext(DbContextOptions options) : base(options)
{
@@ -16,6 +18,8 @@ public ToDoContext(DbContextOptions options) : base(options)
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
+ base.OnModelCreating(modelBuilder);
+
modelBuilder.HasDefaultSchema("ToDos");
modelBuilder.Entity().HasKey(x => x.Id).ForSqlServerIsClustered();
diff --git a/Lesson06/StartOfLesson/ToDo/Migrations/20181216201127_CustomUserWithIntId.Designer.cs b/Lesson06/StartOfLesson/ToDo/Migrations/20181216201127_CustomUserWithIntId.Designer.cs
new file mode 100644
index 0000000..a5a8c20
--- /dev/null
+++ b/Lesson06/StartOfLesson/ToDo/Migrations/20181216201127_CustomUserWithIntId.Designer.cs
@@ -0,0 +1,329 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using ToDoApp.Data;
+
+namespace ToDoApp.Migrations
+{
+ [DbContext(typeof(ToDoContext))]
+ [Migration("20181216201127_CustomUserWithIntId")]
+ partial class CustomUserWithIntId
+ {
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasDefaultSchema("ToDos")
+ .HasAnnotation("ProductVersion", "2.1.4-rtm-31024")
+ .HasAnnotation("Relational:MaxIdentifierLength", 128)
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("ConcurrencyStamp")
+ .IsConcurrencyToken();
+
+ b.Property("Name")
+ .HasMaxLength(256);
+
+ b.Property("NormalizedName")
+ .HasMaxLength(256);
+
+ b.HasKey("Id");
+
+ b.HasIndex("NormalizedName")
+ .IsUnique()
+ .HasName("RoleNameIndex")
+ .HasFilter("[NormalizedName] IS NOT NULL");
+
+ b.ToTable("AspNetRoles");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("ClaimType");
+
+ b.Property("ClaimValue");
+
+ b.Property("RoleId");
+
+ b.HasKey("Id");
+
+ b.HasIndex("RoleId");
+
+ b.ToTable("AspNetRoleClaims");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("ClaimType");
+
+ b.Property("ClaimValue");
+
+ b.Property("UserId");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("AspNetUserClaims");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b =>
+ {
+ b.Property("LoginProvider")
+ .HasMaxLength(128);
+
+ b.Property("ProviderKey")
+ .HasMaxLength(128);
+
+ b.Property("ProviderDisplayName");
+
+ b.Property("UserId");
+
+ b.HasKey("LoginProvider", "ProviderKey");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("AspNetUserLogins");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b =>
+ {
+ b.Property("UserId");
+
+ b.Property("RoleId");
+
+ b.HasKey("UserId", "RoleId");
+
+ b.HasIndex("RoleId");
+
+ b.ToTable("AspNetUserRoles");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b =>
+ {
+ b.Property("UserId");
+
+ b.Property("LoginProvider")
+ .HasMaxLength(128);
+
+ b.Property("Name")
+ .HasMaxLength(128);
+
+ b.Property("Value");
+
+ b.HasKey("UserId", "LoginProvider", "Name");
+
+ b.ToTable("AspNetUserTokens");
+ });
+
+ modelBuilder.Entity("ToDoApp.Areas.Tags.Models.Tag", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("TenantId");
+
+ b.Property("ToDoId");
+
+ b.Property("Value");
+
+ b.HasKey("Id");
+
+ b.HasIndex("TenantId");
+
+ b.HasIndex("ToDoId");
+
+ b.ToTable("Tag");
+ });
+
+ modelBuilder.Entity("ToDoApp.Areas.Tags.Models.Tenant", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Name");
+
+ b.HasKey("Id");
+
+ b.ToTable("Tenant");
+ });
+
+ modelBuilder.Entity("ToDoApp.Models.Status", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Value")
+ .IsRequired();
+
+ b.HasKey("Id");
+
+ b.ToTable("Statuses");
+ });
+
+ modelBuilder.Entity("ToDoApp.Models.ToDo", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Created");
+
+ b.Property("Description");
+
+ b.Property("StatusId");
+
+ b.Property("Title");
+
+ b.HasKey("Id")
+ .HasAnnotation("SqlServer:Clustered", true);
+
+ b.HasIndex("StatusId")
+ .HasName("IX_ToDo_Status");
+
+ b.ToTable("ToDos");
+ });
+
+ modelBuilder.Entity("ToDoApp.Models.ToDoUser", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("AccessFailedCount");
+
+ b.Property("ConcurrencyStamp")
+ .IsConcurrencyToken();
+
+ b.Property("DateOfBirth");
+
+ b.Property("Email")
+ .HasMaxLength(256);
+
+ b.Property("EmailConfirmed");
+
+ b.Property("LockoutEnabled");
+
+ b.Property("LockoutEnd");
+
+ b.Property("NormalizedEmail")
+ .HasMaxLength(256);
+
+ b.Property("NormalizedUserName")
+ .HasMaxLength(256);
+
+ b.Property("PasswordHash");
+
+ b.Property("PhoneNumber");
+
+ b.Property("PhoneNumberConfirmed");
+
+ b.Property("SecurityStamp");
+
+ b.Property("TwoFactorEnabled");
+
+ b.Property("UserName")
+ .HasMaxLength(256);
+
+ b.HasKey("Id");
+
+ b.HasIndex("NormalizedEmail")
+ .HasName("EmailIndex");
+
+ b.HasIndex("NormalizedUserName")
+ .IsUnique()
+ .HasName("UserNameIndex")
+ .HasFilter("[NormalizedUserName] IS NOT NULL");
+
+ b.ToTable("AspNetUsers");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b =>
+ {
+ b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")
+ .WithMany()
+ .HasForeignKey("RoleId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b =>
+ {
+ b.HasOne("ToDoApp.Models.ToDoUser")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b =>
+ {
+ b.HasOne("ToDoApp.Models.ToDoUser")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b =>
+ {
+ b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")
+ .WithMany()
+ .HasForeignKey("RoleId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.HasOne("ToDoApp.Models.ToDoUser")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b =>
+ {
+ b.HasOne("ToDoApp.Models.ToDoUser")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+
+ modelBuilder.Entity("ToDoApp.Areas.Tags.Models.Tag", b =>
+ {
+ b.HasOne("ToDoApp.Areas.Tags.Models.Tenant", "Tenant")
+ .WithMany("Tags")
+ .HasForeignKey("TenantId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.HasOne("ToDoApp.Models.ToDo")
+ .WithMany("Tags")
+ .HasForeignKey("ToDoId");
+ });
+
+ modelBuilder.Entity("ToDoApp.Models.ToDo", b =>
+ {
+ b.HasOne("ToDoApp.Models.Status", "Status")
+ .WithMany("ToDos")
+ .HasForeignKey("StatusId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Lesson06/StartOfLesson/ToDo/Migrations/20181216201127_CustomUserWithIntId.cs b/Lesson06/StartOfLesson/ToDo/Migrations/20181216201127_CustomUserWithIntId.cs
new file mode 100644
index 0000000..2120756
--- /dev/null
+++ b/Lesson06/StartOfLesson/ToDo/Migrations/20181216201127_CustomUserWithIntId.cs
@@ -0,0 +1,314 @@
+using System;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace ToDoApp.Migrations
+{
+ public partial class CustomUserWithIntId : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "AspNetRoles",
+ schema: "ToDos",
+ columns: table => new
+ {
+ Id = table.Column(nullable: false)
+ .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
+ Name = table.Column(maxLength: 256, nullable: true),
+ NormalizedName = table.Column(maxLength: 256, nullable: true),
+ ConcurrencyStamp = table.Column(nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_AspNetRoles", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "AspNetUsers",
+ schema: "ToDos",
+ columns: table => new
+ {
+ Id = table.Column(nullable: false)
+ .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
+ UserName = table.Column(maxLength: 256, nullable: true),
+ NormalizedUserName = table.Column(maxLength: 256, nullable: true),
+ Email = table.Column(maxLength: 256, nullable: true),
+ NormalizedEmail = table.Column(maxLength: 256, nullable: true),
+ EmailConfirmed = table.Column(nullable: false),
+ PasswordHash = table.Column(nullable: true),
+ SecurityStamp = table.Column(nullable: true),
+ ConcurrencyStamp = table.Column(nullable: true),
+ PhoneNumber = table.Column(nullable: true),
+ PhoneNumberConfirmed = table.Column(nullable: false),
+ TwoFactorEnabled = table.Column(nullable: false),
+ LockoutEnd = table.Column(nullable: true),
+ LockoutEnabled = table.Column(nullable: false),
+ AccessFailedCount = table.Column(nullable: false),
+ DateOfBirth = table.Column(nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_AspNetUsers", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Tenant",
+ schema: "ToDos",
+ columns: table => new
+ {
+ Id = table.Column(nullable: false)
+ .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
+ Name = table.Column(nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Tenant", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "AspNetRoleClaims",
+ schema: "ToDos",
+ columns: table => new
+ {
+ Id = table.Column(nullable: false)
+ .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
+ RoleId = table.Column(nullable: false),
+ ClaimType = table.Column(nullable: true),
+ ClaimValue = table.Column(nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
+ table.ForeignKey(
+ name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
+ column: x => x.RoleId,
+ principalSchema: "ToDos",
+ principalTable: "AspNetRoles",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "AspNetUserClaims",
+ schema: "ToDos",
+ columns: table => new
+ {
+ Id = table.Column(nullable: false)
+ .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
+ UserId = table.Column(nullable: false),
+ ClaimType = table.Column(nullable: true),
+ ClaimValue = table.Column(nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
+ table.ForeignKey(
+ name: "FK_AspNetUserClaims_AspNetUsers_UserId",
+ column: x => x.UserId,
+ principalSchema: "ToDos",
+ principalTable: "AspNetUsers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "AspNetUserLogins",
+ schema: "ToDos",
+ columns: table => new
+ {
+ LoginProvider = table.Column(maxLength: 128, nullable: false),
+ ProviderKey = table.Column(maxLength: 128, nullable: false),
+ ProviderDisplayName = table.Column(nullable: true),
+ UserId = table.Column(nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
+ table.ForeignKey(
+ name: "FK_AspNetUserLogins_AspNetUsers_UserId",
+ column: x => x.UserId,
+ principalSchema: "ToDos",
+ principalTable: "AspNetUsers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "AspNetUserRoles",
+ schema: "ToDos",
+ columns: table => new
+ {
+ UserId = table.Column(nullable: false),
+ RoleId = table.Column(nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
+ table.ForeignKey(
+ name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
+ column: x => x.RoleId,
+ principalSchema: "ToDos",
+ principalTable: "AspNetRoles",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_AspNetUserRoles_AspNetUsers_UserId",
+ column: x => x.UserId,
+ principalSchema: "ToDos",
+ principalTable: "AspNetUsers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "AspNetUserTokens",
+ schema: "ToDos",
+ columns: table => new
+ {
+ UserId = table.Column(nullable: false),
+ LoginProvider = table.Column(maxLength: 128, nullable: false),
+ Name = table.Column(maxLength: 128, nullable: false),
+ Value = table.Column(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,
+ principalSchema: "ToDos",
+ principalTable: "AspNetUsers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Tag",
+ schema: "ToDos",
+ columns: table => new
+ {
+ Id = table.Column(nullable: false)
+ .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
+ TenantId = table.Column(nullable: false),
+ Value = table.Column(nullable: true),
+ ToDoId = table.Column(nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Tag", x => x.Id);
+ table.ForeignKey(
+ name: "FK_Tag_Tenant_TenantId",
+ column: x => x.TenantId,
+ principalSchema: "ToDos",
+ principalTable: "Tenant",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_Tag_ToDos_ToDoId",
+ column: x => x.ToDoId,
+ principalSchema: "ToDos",
+ principalTable: "ToDos",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Restrict);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_AspNetRoleClaims_RoleId",
+ schema: "ToDos",
+ table: "AspNetRoleClaims",
+ column: "RoleId");
+
+ migrationBuilder.CreateIndex(
+ name: "RoleNameIndex",
+ schema: "ToDos",
+ table: "AspNetRoles",
+ column: "NormalizedName",
+ unique: true,
+ filter: "[NormalizedName] IS NOT NULL");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_AspNetUserClaims_UserId",
+ schema: "ToDos",
+ table: "AspNetUserClaims",
+ column: "UserId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_AspNetUserLogins_UserId",
+ schema: "ToDos",
+ table: "AspNetUserLogins",
+ column: "UserId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_AspNetUserRoles_RoleId",
+ schema: "ToDos",
+ table: "AspNetUserRoles",
+ column: "RoleId");
+
+ migrationBuilder.CreateIndex(
+ name: "EmailIndex",
+ schema: "ToDos",
+ table: "AspNetUsers",
+ column: "NormalizedEmail");
+
+ migrationBuilder.CreateIndex(
+ name: "UserNameIndex",
+ schema: "ToDos",
+ table: "AspNetUsers",
+ column: "NormalizedUserName",
+ unique: true,
+ filter: "[NormalizedUserName] IS NOT NULL");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Tag_TenantId",
+ schema: "ToDos",
+ table: "Tag",
+ column: "TenantId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Tag_ToDoId",
+ schema: "ToDos",
+ table: "Tag",
+ column: "ToDoId");
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "AspNetRoleClaims",
+ schema: "ToDos");
+
+ migrationBuilder.DropTable(
+ name: "AspNetUserClaims",
+ schema: "ToDos");
+
+ migrationBuilder.DropTable(
+ name: "AspNetUserLogins",
+ schema: "ToDos");
+
+ migrationBuilder.DropTable(
+ name: "AspNetUserRoles",
+ schema: "ToDos");
+
+ migrationBuilder.DropTable(
+ name: "AspNetUserTokens",
+ schema: "ToDos");
+
+ migrationBuilder.DropTable(
+ name: "Tag",
+ schema: "ToDos");
+
+ migrationBuilder.DropTable(
+ name: "AspNetRoles",
+ schema: "ToDos");
+
+ migrationBuilder.DropTable(
+ name: "AspNetUsers",
+ schema: "ToDos");
+
+ migrationBuilder.DropTable(
+ name: "Tenant",
+ schema: "ToDos");
+ }
+ }
+}
diff --git a/Lesson06/StartOfLesson/ToDo/Migrations/20181216202916_MakeToDoUserDateOfBirthOptional.Designer.cs b/Lesson06/StartOfLesson/ToDo/Migrations/20181216202916_MakeToDoUserDateOfBirthOptional.Designer.cs
new file mode 100644
index 0000000..be7ba40
--- /dev/null
+++ b/Lesson06/StartOfLesson/ToDo/Migrations/20181216202916_MakeToDoUserDateOfBirthOptional.Designer.cs
@@ -0,0 +1,329 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using ToDoApp.Data;
+
+namespace ToDoApp.Migrations
+{
+ [DbContext(typeof(ToDoContext))]
+ [Migration("20181216202916_MakeToDoUserDateOfBirthOptional")]
+ partial class MakeToDoUserDateOfBirthOptional
+ {
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasDefaultSchema("ToDos")
+ .HasAnnotation("ProductVersion", "2.1.4-rtm-31024")
+ .HasAnnotation("Relational:MaxIdentifierLength", 128)
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("ConcurrencyStamp")
+ .IsConcurrencyToken();
+
+ b.Property("Name")
+ .HasMaxLength(256);
+
+ b.Property("NormalizedName")
+ .HasMaxLength(256);
+
+ b.HasKey("Id");
+
+ b.HasIndex("NormalizedName")
+ .IsUnique()
+ .HasName("RoleNameIndex")
+ .HasFilter("[NormalizedName] IS NOT NULL");
+
+ b.ToTable("AspNetRoles");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("ClaimType");
+
+ b.Property("ClaimValue");
+
+ b.Property("RoleId");
+
+ b.HasKey("Id");
+
+ b.HasIndex("RoleId");
+
+ b.ToTable("AspNetRoleClaims");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("ClaimType");
+
+ b.Property("ClaimValue");
+
+ b.Property("UserId");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("AspNetUserClaims");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b =>
+ {
+ b.Property("LoginProvider")
+ .HasMaxLength(128);
+
+ b.Property("ProviderKey")
+ .HasMaxLength(128);
+
+ b.Property("ProviderDisplayName");
+
+ b.Property("UserId");
+
+ b.HasKey("LoginProvider", "ProviderKey");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("AspNetUserLogins");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b =>
+ {
+ b.Property("UserId");
+
+ b.Property("RoleId");
+
+ b.HasKey("UserId", "RoleId");
+
+ b.HasIndex("RoleId");
+
+ b.ToTable("AspNetUserRoles");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b =>
+ {
+ b.Property("UserId");
+
+ b.Property("LoginProvider")
+ .HasMaxLength(128);
+
+ b.Property("Name")
+ .HasMaxLength(128);
+
+ b.Property("Value");
+
+ b.HasKey("UserId", "LoginProvider", "Name");
+
+ b.ToTable("AspNetUserTokens");
+ });
+
+ modelBuilder.Entity("ToDoApp.Areas.Tags.Models.Tag", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("TenantId");
+
+ b.Property("ToDoId");
+
+ b.Property("Value");
+
+ b.HasKey("Id");
+
+ b.HasIndex("TenantId");
+
+ b.HasIndex("ToDoId");
+
+ b.ToTable("Tag");
+ });
+
+ modelBuilder.Entity("ToDoApp.Areas.Tags.Models.Tenant", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Name");
+
+ b.HasKey("Id");
+
+ b.ToTable("Tenant");
+ });
+
+ modelBuilder.Entity("ToDoApp.Models.Status", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Value")
+ .IsRequired();
+
+ b.HasKey("Id");
+
+ b.ToTable("Statuses");
+ });
+
+ modelBuilder.Entity("ToDoApp.Models.ToDo", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Created");
+
+ b.Property("Description");
+
+ b.Property("StatusId");
+
+ b.Property("Title");
+
+ b.HasKey("Id")
+ .HasAnnotation("SqlServer:Clustered", true);
+
+ b.HasIndex("StatusId")
+ .HasName("IX_ToDo_Status");
+
+ b.ToTable("ToDos");
+ });
+
+ modelBuilder.Entity("ToDoApp.Models.ToDoUser", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("AccessFailedCount");
+
+ b.Property("ConcurrencyStamp")
+ .IsConcurrencyToken();
+
+ b.Property("DateOfBirth");
+
+ b.Property("Email")
+ .HasMaxLength(256);
+
+ b.Property("EmailConfirmed");
+
+ b.Property("LockoutEnabled");
+
+ b.Property("LockoutEnd");
+
+ b.Property("NormalizedEmail")
+ .HasMaxLength(256);
+
+ b.Property("NormalizedUserName")
+ .HasMaxLength(256);
+
+ b.Property("PasswordHash");
+
+ b.Property("PhoneNumber");
+
+ b.Property("PhoneNumberConfirmed");
+
+ b.Property("SecurityStamp");
+
+ b.Property("TwoFactorEnabled");
+
+ b.Property("UserName")
+ .HasMaxLength(256);
+
+ b.HasKey("Id");
+
+ b.HasIndex("NormalizedEmail")
+ .HasName("EmailIndex");
+
+ b.HasIndex("NormalizedUserName")
+ .IsUnique()
+ .HasName("UserNameIndex")
+ .HasFilter("[NormalizedUserName] IS NOT NULL");
+
+ b.ToTable("AspNetUsers");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b =>
+ {
+ b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")
+ .WithMany()
+ .HasForeignKey("RoleId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b =>
+ {
+ b.HasOne("ToDoApp.Models.ToDoUser")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b =>
+ {
+ b.HasOne("ToDoApp.Models.ToDoUser")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b =>
+ {
+ b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")
+ .WithMany()
+ .HasForeignKey("RoleId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.HasOne("ToDoApp.Models.ToDoUser")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b =>
+ {
+ b.HasOne("ToDoApp.Models.ToDoUser")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+
+ modelBuilder.Entity("ToDoApp.Areas.Tags.Models.Tag", b =>
+ {
+ b.HasOne("ToDoApp.Areas.Tags.Models.Tenant", "Tenant")
+ .WithMany("Tags")
+ .HasForeignKey("TenantId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.HasOne("ToDoApp.Models.ToDo")
+ .WithMany("Tags")
+ .HasForeignKey("ToDoId");
+ });
+
+ modelBuilder.Entity("ToDoApp.Models.ToDo", b =>
+ {
+ b.HasOne("ToDoApp.Models.Status", "Status")
+ .WithMany("ToDos")
+ .HasForeignKey("StatusId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Lesson06/StartOfLesson/ToDo/Migrations/20181216202916_MakeToDoUserDateOfBirthOptional.cs b/Lesson06/StartOfLesson/ToDo/Migrations/20181216202916_MakeToDoUserDateOfBirthOptional.cs
new file mode 100644
index 0000000..cbb9aed
--- /dev/null
+++ b/Lesson06/StartOfLesson/ToDo/Migrations/20181216202916_MakeToDoUserDateOfBirthOptional.cs
@@ -0,0 +1,29 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace ToDoApp.Migrations
+{
+ public partial class MakeToDoUserDateOfBirthOptional : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AlterColumn(
+ name: "DateOfBirth",
+ schema: "ToDos",
+ table: "AspNetUsers",
+ nullable: true,
+ oldClrType: typeof(DateTime));
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AlterColumn(
+ name: "DateOfBirth",
+ schema: "ToDos",
+ table: "AspNetUsers",
+ nullable: false,
+ oldClrType: typeof(DateTime),
+ oldNullable: true);
+ }
+ }
+}
diff --git a/Lesson06/StartOfLesson/ToDo/Migrations/ToDoContextModelSnapshot.cs b/Lesson06/StartOfLesson/ToDo/Migrations/ToDoContextModelSnapshot.cs
index 55e67c0..569a016 100644
--- a/Lesson06/StartOfLesson/ToDo/Migrations/ToDoContextModelSnapshot.cs
+++ b/Lesson06/StartOfLesson/ToDo/Migrations/ToDoContextModelSnapshot.cs
@@ -16,10 +16,156 @@ protected override void BuildModel(ModelBuilder modelBuilder)
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("ToDos")
- .HasAnnotation("ProductVersion", "2.1.2-rtm-30932")
+ .HasAnnotation("ProductVersion", "2.1.4-rtm-31024")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("ConcurrencyStamp")
+ .IsConcurrencyToken();
+
+ b.Property("Name")
+ .HasMaxLength(256);
+
+ b.Property("NormalizedName")
+ .HasMaxLength(256);
+
+ b.HasKey("Id");
+
+ b.HasIndex("NormalizedName")
+ .IsUnique()
+ .HasName("RoleNameIndex")
+ .HasFilter("[NormalizedName] IS NOT NULL");
+
+ b.ToTable("AspNetRoles");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("ClaimType");
+
+ b.Property("ClaimValue");
+
+ b.Property("RoleId");
+
+ b.HasKey("Id");
+
+ b.HasIndex("RoleId");
+
+ b.ToTable("AspNetRoleClaims");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("ClaimType");
+
+ b.Property("ClaimValue");
+
+ b.Property("UserId");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("AspNetUserClaims");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b =>
+ {
+ b.Property("LoginProvider")
+ .HasMaxLength(128);
+
+ b.Property("ProviderKey")
+ .HasMaxLength(128);
+
+ b.Property("ProviderDisplayName");
+
+ b.Property("UserId");
+
+ b.HasKey("LoginProvider", "ProviderKey");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("AspNetUserLogins");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b =>
+ {
+ b.Property("UserId");
+
+ b.Property("RoleId");
+
+ b.HasKey("UserId", "RoleId");
+
+ b.HasIndex("RoleId");
+
+ b.ToTable("AspNetUserRoles");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b =>
+ {
+ b.Property("UserId");
+
+ b.Property("LoginProvider")
+ .HasMaxLength(128);
+
+ b.Property("Name")
+ .HasMaxLength(128);
+
+ b.Property("Value");
+
+ b.HasKey("UserId", "LoginProvider", "Name");
+
+ b.ToTable("AspNetUserTokens");
+ });
+
+ modelBuilder.Entity("ToDoApp.Areas.Tags.Models.Tag", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("TenantId");
+
+ b.Property("ToDoId");
+
+ b.Property("Value");
+
+ b.HasKey("Id");
+
+ b.HasIndex("TenantId");
+
+ b.HasIndex("ToDoId");
+
+ b.ToTable("Tag");
+ });
+
+ modelBuilder.Entity("ToDoApp.Areas.Tags.Models.Tenant", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Name");
+
+ b.HasKey("Id");
+
+ b.ToTable("Tenant");
+ });
+
modelBuilder.Entity("ToDoApp.Models.Status", b =>
{
b.Property("Id")
@@ -57,6 +203,117 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("ToDos");
});
+ modelBuilder.Entity("ToDoApp.Models.ToDoUser", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("AccessFailedCount");
+
+ b.Property("ConcurrencyStamp")
+ .IsConcurrencyToken();
+
+ b.Property("DateOfBirth");
+
+ b.Property("Email")
+ .HasMaxLength(256);
+
+ b.Property("EmailConfirmed");
+
+ b.Property("LockoutEnabled");
+
+ b.Property("LockoutEnd");
+
+ b.Property("NormalizedEmail")
+ .HasMaxLength(256);
+
+ b.Property("NormalizedUserName")
+ .HasMaxLength(256);
+
+ b.Property("PasswordHash");
+
+ b.Property("PhoneNumber");
+
+ b.Property("PhoneNumberConfirmed");
+
+ b.Property("SecurityStamp");
+
+ b.Property("TwoFactorEnabled");
+
+ b.Property("UserName")
+ .HasMaxLength(256);
+
+ b.HasKey("Id");
+
+ b.HasIndex("NormalizedEmail")
+ .HasName("EmailIndex");
+
+ b.HasIndex("NormalizedUserName")
+ .IsUnique()
+ .HasName("UserNameIndex")
+ .HasFilter("[NormalizedUserName] IS NOT NULL");
+
+ b.ToTable("AspNetUsers");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b =>
+ {
+ b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")
+ .WithMany()
+ .HasForeignKey("RoleId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b =>
+ {
+ b.HasOne("ToDoApp.Models.ToDoUser")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b =>
+ {
+ b.HasOne("ToDoApp.Models.ToDoUser")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b =>
+ {
+ b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole")
+ .WithMany()
+ .HasForeignKey("RoleId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.HasOne("ToDoApp.Models.ToDoUser")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b =>
+ {
+ b.HasOne("ToDoApp.Models.ToDoUser")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+ });
+
+ modelBuilder.Entity("ToDoApp.Areas.Tags.Models.Tag", b =>
+ {
+ b.HasOne("ToDoApp.Areas.Tags.Models.Tenant", "Tenant")
+ .WithMany("Tags")
+ .HasForeignKey("TenantId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.HasOne("ToDoApp.Models.ToDo")
+ .WithMany("Tags")
+ .HasForeignKey("ToDoId");
+ });
+
modelBuilder.Entity("ToDoApp.Models.ToDo", b =>
{
b.HasOne("ToDoApp.Models.Status", "Status")
diff --git a/Lesson06/StartOfLesson/ToDo/Models/ToDoUser.cs b/Lesson06/StartOfLesson/ToDo/Models/ToDoUser.cs
new file mode 100644
index 0000000..c07920c
--- /dev/null
+++ b/Lesson06/StartOfLesson/ToDo/Models/ToDoUser.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Identity;
+
+namespace ToDoApp.Models
+{
+ public class ToDoUser : IdentityUser
+ {
+ public DateTime? DateOfBirth { get; set; }
+
+ }
+}
diff --git a/Lesson06/StartOfLesson/ToDo/Properties/launchSettings.json b/Lesson06/StartOfLesson/ToDo/Properties/launchSettings.json
index 748d1b2..9ac3d91 100644
--- a/Lesson06/StartOfLesson/ToDo/Properties/launchSettings.json
+++ b/Lesson06/StartOfLesson/ToDo/Properties/launchSettings.json
@@ -18,7 +18,7 @@
"ToDo": {
"commandName": "Project",
"launchBrowser": true,
- "applicationUrl": "http://localhost:5000",
+ "applicationUrl": "http://localhost:5000;https://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
diff --git a/Lesson06/StartOfLesson/ToDo/Startup.cs b/Lesson06/StartOfLesson/ToDo/Startup.cs
index 339e1ff..9e1ffc1 100644
--- a/Lesson06/StartOfLesson/ToDo/Startup.cs
+++ b/Lesson06/StartOfLesson/ToDo/Startup.cs
@@ -1,14 +1,21 @@
-using System.Threading.Tasks;
+using System;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
using ToDoApp.Areas.Tags.Data;
using ToDoApp.Data;
using ToDoApp.Infrastructure;
+using ToDoApp.Models;
using ToDoApp.Services;
using WebServerUtilities;
@@ -40,13 +47,25 @@ public void ConfigureServices(IServiceCollection services)
options.MinimumSameSitePolicy = SameSiteMode.None;
});
- services.AddDbContext(config => config.UseSqlServer(Configuration.GetConnectionString("ToDoApp")));
+ //configure entity framework
+ services.AddDbContext(config => config.UseSqlServer(Configuration.GetConnectionString("ToDoApp")));
+ // configure identity provider
+ services.AddIdentity>()
+ .AddEntityFrameworkStores()
+ // Known defect that prevents us from using Role based with out of the box Identity
+ // Known defect in .NET Core v2.1: https://github.com/aspnet/Identity/issues/1813
+ .AddDefaultUI()
+ .AddDefaultTokenProviders()
+ .AddRoleManager>>();
+
+ // configure authentication for cookies
+ services.AddAuthentication().AddCookie();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env)
+ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILogger logger)
{
if (env.IsDevelopment())
{
@@ -56,11 +75,14 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseExceptionHandler("/Home/Error");
}
+ app.UseHttpsRedirection();
+
app.UseStatusCodePagesWithReExecute("/Error", "?statusCode={0}");
app.UseMiddleware