Vaibhav Saxena

Vaibhav Saxena

  • NA
  • 14
  • 780

How to make DepartmentAdmin job/cls frm abstract Admin class

Apr 6 2017 12:53 AM
Hi friends,I am working on HR and Employee Management project. Normally, we keep few tables like Department, Employee, HR, Manager etc. However, i'm thinking about designing an abstract class which can be implemented to do administration of any business entity passed as a parameter. I did that and i am able to create different admin classes but i cant pass the IEnumerable of entity object or the single entity object for displaying, updation, deletion. Why im doing it? I dont want to populate basic tables, which will be used by other entities and business layer - with data, from a script. I want an admin panel. Moreover, this style will allow me to add new entity and create admin class of new entity by using the abstract class. Thus, i can do CRUD operations on newly created businesses entity from admin panel. public abstract class Admin { public Object obj; public List objlist; public virtual void CreateAdmin() { } public virtual List GetDepartments() {/* i cant tightly couple it by passing Departmentobject because it should work with any business entity seamlessly */return objlist;} public virtual void UpdateAdmin() { } } -----------&&&&--------- public class DepartmentAdmin : Admin { private int _deptid; private string _deptname; public DepartmentAdmin(int deptid,string deptname) { _deptid=deptid;_deptname=deptname; } public override void CreateAdmin() { // const spname="createdepartment"; Department dept=new Department(); dept.DepartmentId= this._deptid; dept.DepartmentName= this._deptname; // call to dataAccess layer dataserver classDataServer ds= new DataServer();ds.runTransaction(spname); } } Either UI or Business Layer will instantiate Department Admin class to create new Department object and save it to Database, /* I am unable to do this public override List GetDepartments(Department d) Or public override void UpdateFepartment(Department d) Because no method takes one argument, it wont work even if i change base class fuction definition to public virtual void UpdateAdmin(Object o) Or to public override void UpdateAdmin(Admin a) */What can be the solution ? I want to be able to create LeaveAdmin class for leaves entity, similarly for qualification, designation, allowances entities etc. (i.e. for any new requirement).I know there are problems in data access layer code too becaue i havent yet passed business entity with call to dataserver.runtransaction(spname) method.I think with MVC-Ef it would be much easier to implement. Sample code and design suggestions will be highly appreciated. Also tell me how can I throw in Dependency Inversion using structuremap, unity, automapper (I never did that). I have one more question: what is the best way to store data in tables which need not be changed unless rarely required ? As an example, in situations, where basic tables like Department, Leaves, Designation etc. need not be instantiated again and again other than storing default values. In these situations, is it better not to create entity classes of these tables by letting EF know it using Data Annotations or they should be used as abstract classes ? Thanks in advance to everyone for helping :)

Answers (2)