Asp.net mvc inheritance controllers

I am learning asp.net mvc, and in my test project I have some problems with inheritance: In my model, I use inheritanse in several entities:

public class Employee:Entity
    {
        /* few public properties */
    }

This is the base class. And the descendants:

public class RecruitmentOfficeEmployee: Employee
    {
        public virtual RecruitmentOffice AssignedOnRecruitmentOffice { get; set; }
    }

public class ResearchInstituteEmployee: Employee
    {
        public virtual ResearchInstitute AssignedOnResearchInstitute { get; set; }
    }

I want to implement simple CRUD operations for each element.

What is the best way to implement controllers and views among descendants: - One controller for each descendant; - Inheritance of the controller;
 - general controller; - General methods in one controller.

Or maybe there is another way?

ORM - NHibernate, , . -, - , , .

, )

+3
1

, , .

, , , . , . , , .

, ( IMO):

public class EmployeeController : Controller
{
    public enum EmployeeType
    {
        RecruitmentOffice,
        ResearchInstitute
    }

    public ActionResult Details(int id, EmployeeType type)
    {            
        switch (type)
        {
            case EmployeeType.RecruitmentOffice:
                // load repository
                // load domain object
                // load view specific to recruitment office
                break;
            case EmployeeType.ResearchInstitute:
                // load repository
                // load domain object
                // load view specific to recruitment office
                break;
        }
    }
}
+2

Source: https://habr.com/ru/post/1747065/


All Articles