Need help with figuring out a better method of my application layout, please

I am working as the sole .Net developer at a company and I have been tasked with a very large and complex project, an internal intranet site for inventory and time tracking. I have built a project that contains 3 applications, WebUI, Data Access Layer, and Core.

The WebUI is my normal MVC stuff, the DAL contains the models used by Entity Framework for the MS SQL DB, and Core currently holds all the helper classes I have developed. This has worked fine and well for me so far but now I have ran into a problem that I can’t figure out a decent solution to and I think it stems from the base design of my system.

In my timesheet controller I have a private method called GetTimesheetData which takes a data and an employeeID as input parameters, does some logic for ACL and some queries against the DB to get then returns an instance of a ViewModel with all the data in it. This code now needs to be accessed by other classes outside of this controller. This has presented me with the problem of where to move this code or if it needs to be broken up and moved into multiple places (what places I don’t know).

I was thinking about carving it up and moving the queries into my helper classes which do things like getting basic data from the DB (employee IDs, employee info, etc) and also things like some basic business logic like finding the pay period a given date is in or where or not a person is a manger and can approve timesheets.

How can I improve the design of the application to avoid having to recode the entire GetTimesheetData method into multiple places causing a headache if anything has to change in it?

In continuing to read things I can find on Google I am starting to think that I might need to add a new application for “Business Logic” that would contain models and more complex queries then what my helpers have or maybe extend my Core application to encompass this as well.

If I’m understanding correctly, your web tier references core, and core references the DAL.

In your core layer, create a service class that exposes the GetTimesheetData method like

public class TimesheetService
    public List<TimesheetDataModel> GetTimesheetData()
        // call DAL to get data

Then in your controllers and elsewhere, use this service

public class TimesheetController : Controller
    private readonly TimesheetService _timesheetService = new TimesheetService();

    public ActionResult Get()
        var data = _timesheetService.GetTimesheetData();
        return Json(data, JsonRequestBehavior.AllowGet);   



Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *