ApplicationUser

Let's start with the entity that will be used to store all the user-related info. We'll use it for a number of useful tasks, such as keeping record of who created each quiz, tracking those who will take the quizzes, handling the login and authentication phase, and more.

Switch to Solution Explorer, then do the following:

  1. Create a new /Data/ folder at the root level of the TestMakerFreeWebApp project; this will be where all our EntityFramework-related classes will reside.
  2. Create a /Data/Models/ folder.
  3. Add a new ASP.NET Core | Code | Class file, name it ApplicationUser.cs, and replace the sample code with the following:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace TestMakerFreeWebApp.Data
{
public class ApplicationUser
{
#region Constructor
public ApplicationUser()
{

}
#endregion

#region Properties
[Key]
[Required]
public string Id { get; set; }

[Required]
[MaxLength(128)]
public string UserName { get; set; }

[Required]
public string Email { get; set; }

public string DisplayName { get; set; }

public string Notes { get; set; }

[Required]
public int Type { get; set; }

[Required]
public int Flags { get; set; }

[Required]
public DateTime CreatedDate { get; set; }

[Required]
public DateTime LastModifiedDate { get; set; }
#endregion
}
}

Note how there are no foreign keys pointing at quizzes, questions, and so on here; there's nothing strange about that, as these are all one-to-many relationships that will be handled from the other side.

We can ask ourselves why we used the ApplicationUser class name instead of User. The answer is pretty simple--ApplicationUser is the conventional name given to the custom implementation of the IdentityUser base class used by the ASP.NET Identity module. We’re using that in compliance with that convention, as we plan to implement this module later on.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.29.71