✨ Introduction
In Part 1, we explored the architecture, database schema, and Razor screens for the HospitalManagement system.
In this second part, we’ll dive into the Controllers and Services. These layers handle business logic, data persistence, and communication between Razor views and the database.
⚙️ Controllers Overview
Controllers are responsible for:
Handling HTTP requests (
GET,POST).Calling the appropriate service methods.
Returning data to Razor views.
Each module has its own controller:
PatientController
StaffController
FinanceController
NotificationController
ChatController
👨⚕️ PatientController
csharp
public class PatientController : Controller
{
private readonly IPatientService _patientService;
public PatientController(IPatientService patientService)
{
_patientService = patientService;
}
public IActionResult Index()
{
var patients = _patientService.GetAll();
return View(patients);
}
[HttpPost]
public IActionResult Create(Patient patient)
{
_patientService.Add(patient);
return RedirectToAction("Index");
}
}
🔎 Explanation
Index()→ Fetches all patients from the service and passes them to the Razor view.Create()→ Adds a new patient record via the service.
👩⚕️ StaffController
csharp
public class StaffController : Controller
{
private readonly IStaffService _staffService;
public StaffController(IStaffService staffService)
{
_staffService = staffService;
}
public IActionResult Index()
{
var staff = _staffService.GetAll();
return View(staff);
}
[HttpPost]
public IActionResult Create(Staff staff)
{
_staffService.Add(staff);
return RedirectToAction("Index");
}
}
💳 FinanceController
csharp
public class FinanceController : Controller
{
private readonly IFinanceService _financeService;
public FinanceController(IFinanceService financeService)
{
_financeService = financeService;
}
public IActionResult Index()
{
var invoices = _financeService.GetAll();
return View(invoices);
}
[HttpPost]
public IActionResult Create(Invoice invoice)
{
_financeService.Add(invoice);
return RedirectToAction("Index");
}
}

Join the conversation! Your thoughts help the community grow.