Dotnet
Authentication and Authorization - Registration Part 2
  •  

Add Person Domain

PRO

I finished! On to the next chapter

Outline

Demo: Add Person Domain

In Conduit.Data Project

House cleaning
  • Delete Class1.cs
Add new class named Account
  • Make it public
Add new class named Person
  • Make it public
  • Remove and Sort Usings
  • Add the Table Attribute specifying People as the table name.
Add the following properties
  • Id (int)
  • UserName (string)
  • Bio (string)
  • Image (string)
  • Account (Account)
Add the following Attribute to the Id Property
  • Key
Add the following Attribute to the UserName Property
  • Required
  • StringLength
    • Set the max lenth at 50 (or any length you desire)
Add the following Attribute to the Bio Property
  • StringLength
    • Set the max lenth at 200 (or any length you desire)
Add the following Attribute to the Image Property
  • StringLength
    • Set the max lenth at 200 (or any length you desire)

Here's the code for Conduit.Data.Account.cs:

namespace Conduit.Data
{
    public class Account
    {
    }
}

Here's the code for Conduit.Data.Person.cs

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Conduit.Data
{
    [Table("People")]
    public class Person
    {
        [Key]
        public int Id { get; set; }

        [Required]
        [StringLength(50)]
        public string UserName { get; set; }

        [StringLength(200)]
        public string Bio { get; set; }

        [Required]
        [StringLength(200)]
        public string Image { get; set; }

        public Account Account { get; set; }
    }
}