public IActionResult ConfirmDelegation([FromServices] EmployeeService es, [FromServices] Emailservice ems, int employeeId, DateTime startDate, DateTime endDate) { if (!(HttpContext.Session.GetString("role") == EmployeeRole.DEPTHEAD)) { return(RedirectToAction(HttpContext.Session.GetString("role"), "Home")); } //check dates if (endDate < startDate) { TempData["errmsg"] = "End Date cannot be before Start Date."; return(RedirectToAction("Delegate")); } if (startDate < DateTime.Today) { TempData["errmsg"] = "Invalid date input. Ensure both Start Date and End Date are selected and Start Date should be today or later."; return(RedirectToAction("Delegate")); } if (es.OverlappingAppointment(employeeId, startDate, endDate)) { TempData["errmsg"] = "An employee has already been appointed as the Acting Dept Head for the period."; return(RedirectToAction("Delegate")); } es.AddActingDepartmentHead(employeeId, startDate, endDate); ems.sendDelegateAppointmentEmail(employeeId, startDate, endDate); return(RedirectToAction("DepartmentHead", "Home")); }