Creating the common layer

We will start by creating the common layer first. This layer is the common layer and is referenced by all the other layers. It contains some core classes and helper functions which will be used by each layer. The data access layer will create a database from the entities defined in the common layer. The business layer will use the entities and business objects defined in the common layer to perform data manipulations and the presentation layer will use it to bind the models with the views.

To start with, create a new Class Library (.NET Core) project. Once it is created, we will add a few entities specific to the Tenant Management System:

The following entity will hold user profile information and is derived from the IdentityUser class provided in the ASP.NET Core Identity Framework. We will use ASP.NET Identity Core and Identity Server to perform user authentication and authorization. To learn more about Identity Core and how to configure it in an ASP.NET application, please refer to Chapter 10, Security Practices with .NET Core.

Here is the code of the ApplicationUser class:

    public class ApplicationUser : IdentityUser 
{
}

Normally, when designing the entity models, all the generic properties should reside under the base entity. So, we will create a BaseEntity class, which will be inherited by all child entities.

Here is the code for the BaseEntity class:

    public abstract class BaseEntity 
{

public BaseEntity()
{
this.CreatedOn = DateTime.Now;
this.UpdatedOn = DateTime.Now;
this.State = (int)EntityState.New;
}
public string CreatedBy { get; set; }
public DateTime CreatedOn { get; set; }
public string UpdatedBy { get; set; }
public DateTime UpdatedOn { get; set; }

[NotMapped]
public int State { get; set; }

public enum EntityState
{
New=1,
Update=2,
Delete =3,
Ignore=4
}
}

In our BaseEntity class, we have four transactional properties--CreatedBy, CreatedOn, UpdatedOn, and UpdatedBy, which are common for every entity derived from it. These fields are good to store the user information and the transaction date time. EntityState is used to manage the state of each object and helps the developer to set states when manipulating a grid or a collection.

..................Content has been hidden....................

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