I am having issue creating N-tier application asp.net web-api. So far this is what I created

Class Library
 BusinessObject(POCO Model)
 DAL(Data Access Layer)
 BLL(Business Logic)

Main app
 - Controller API

I added the following reference to each class library

BusinessObject
DAL
 - BusinessObject
BLL
 - DAL
 - BusinessObject
MainApp
 - BusinessObject
 - BLL

I created the app using Visual Studio, and I want to use EntityFramework Code first approach first ( I dont have a database setup yet)

My issues is I am not to sure how to setup an N-tier data layer, and calling the business logic properly.

BusinessObject

public class Gender:Base
{
    [Required]
    [MaxLength(255)]
    public string Description { get; set; }
}

public abstract class Base
{
    [Key][Required]
    public int ID { get; set; }

    public Boolean isValid { get; set; }

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

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

Business Layer

public class GenderBLL
{
    public GenderDAL ListGenders()
    {
        GenderDAL GBLL = new GenderDAL();
        return GBLL;
    }
}

This is where I believe I am failing

MainApp

Controller
        public GenderDAL GetAllGenders()
        {
            GenderBLL GBLL = new GenderBLL();
            return GBLL.ListGenders();
        }

Data Access Layer

public class GenderDAL
{
    public IEnumerable<Gender> GetGenders()
    {
        Gender[] balance = new Gender[10];

        Gender test = new Gender { ID = 1, Description = "Male", CreatedOn = DateTime.Now};

        balance[0] = test;
        balance[1] = test;

        return balance;
    }
}

Now i am using EntityFramework, and if I understand this properly I have to setup a DBContext for the entire applications for one connections, where would I set this up. Are there a recent tutorial on DAL with Webapi? Is there a way for me to call from my controller to the business layer without referencing the DAL layer.

Thank you

Related posts

Recent Viewed