public ActionResult ViewDelegate(Models.Delegate d, string delegatedhead, string sessionId) { Employee emp = EmployeeService.GetUserBySessionId(sessionId); long deptId = emp.DeptId; List <Employee> employees = RepresentativeService.GetEmployeesByDepartment(deptId); long headId = DepartmentService.GetCurrentHead(deptId); Employee e = EmployeeDAO.GetEmployeeById(headId); ViewData["currentHead"] = e; ViewData["employees"] = employees; ViewData["timeErr"] = false; bool all = DelegateService.CheckPreviousHeadForNav(deptId); ViewData["all"] = all; ViewData["sessionId"] = sessionId; if (delegatedhead == null && d.Employee == null) { if (DelegateService.CheckDelegatedByDept(deptId)) { ViewData["delegated"] = true; } else { ViewData["delegated"] = false; } return(View()); } else if (delegatedhead == null && d.Employee != null) { d.Department = new Department(); d.Department.DeptId = deptId; bool isThereDelegate = DelegateService.CheckDelegatedByDept(deptId); bool timeErr = (d.FromDate < DateTime.Now && d.ToDate < DateTime.Now); ViewData["timeErr"] = timeErr; if (!isThereDelegate && !timeErr) { DelegateService.AddNewDelegate(d, headId); EmailNotification notice = new EmailNotification(); Employee MailReceiver = EmployeeService.GetEmployeeById(d.Employee.EmpId); notice.ReceiverMailAddress = MailReceiver.Email; notice.From = d.FromDate; notice.To = d.ToDate; Task.Run(() => emailService.SendMail(notice, EmailTrigger.ON_DELEGATED_AS_DEPT_HEAD)); } bool allnav = DelegateService.CheckPreviousHeadForNav(deptId); ViewData["all"] = allnav; long head = DepartmentService.GetCurrentHead(deptId); Employee h = EmployeeDAO.GetEmployeeById(head); ViewData["currentHead"] = h; if (timeErr) { ViewData["delegated"] = false; } else { ViewData["delegated"] = true; } return(View()); } else if (delegatedhead != null && d.Employee == null) { EmailNotification notice = new EmailNotification(); long head = DepartmentService.GetCurrentHead(deptId); Employee MailReceiver = EmployeeDAO.GetEmployeeById(head); notice.ReceiverMailAddress = MailReceiver.Email; DelegateService.DelegateToPreviousHead(deptId); Task.Run(() => emailService.SendMail(notice, EmailTrigger.ON_REMOVED_DEPT_HEAD)); List <Employee> emps = RepresentativeService.GetEmployeesByDepartment(deptId); ViewData["employees"] = emps; ViewData["delegated"] = false; bool show = DelegateService.CheckPreviousHeadForNav(deptId); ViewData["all"] = show; return(View()); } else { ViewData["delegated"] = false; return(View()); } }
public ActionResult All(string sessionid) { if (sessionid == null) { RedirectToAction("Login"); } // for login employee sessin data Employee emp = EmployeeService.GetUserBySessionId(sessionid); string empRole = emp.EmpRole; string userName = emp.UserName; string empDisplayRole = emp.EmpDisplayRole; if (empRole == "STORE_CLERK" || empRole == "STORE_SUPERVISOR" || empRole == "STORE_MANAGER") { ViewData["userName"] = userName; ViewData["sessionId"] = sessionid; return(View("~/Views/StoreLandingPage/Home.cshtml")); } else if ((empRole == "EMPLOYEE" || empRole == "REPRESENTATIVE") && (empDisplayRole != "HEAD")) { return(RedirectToAction("NewRequisition", "Requisition", new { sessionId = sessionid })); } //else if ((empRole=="HEAD" && empDisplayRole=="HEAD")) //{ // return RedirectToAction("GetPendingRequisitions","Requisition",new { sessionId=sessionid}); //} else if ((empRole == "HEAD" && empDisplayRole == "HEAD")) { bool between = DelegateService.CheckDate(emp.DeptId); bool after = DelegateService.AfterDate(emp.DeptId); if (between && !after) { return(RedirectToAction("ViewDelegate", "Delegate", new { sessionId = sessionid })); } else if (!between && !after) { return(RedirectToAction("GetPendingRequisitions", "Requisition", new { sessionId = sessionid })); } else if (!between && after) { DelegateService.DelegateToPreviousHead(emp.DeptId); return(RedirectToAction("GetPendingRequisitions", "Requisition", new { sessionId = sessionid })); } else { return(RedirectToAction("GetPendingRequisitions", "Requisition", new { sessionId = sessionid })); } } else if ((empRole == "HEAD" && empDisplayRole == "EMPLOYEE")) { bool between = DelegateService.CheckDate(emp.DeptId); bool after = DelegateService.AfterDate(emp.DeptId); if (between && !after) { return(RedirectToAction("GetPendingRequisitions", "Requisition", new { sessionId = sessionid })); } else if (!between && !after) { return(RedirectToAction("NewRequisition", "Requisition", new { sessionId = sessionid })); } else if (!between && after) { DelegateService.DelegateToPreviousHead(emp.DeptId); return(RedirectToAction("NewRequisition", "Requisition", new { sessionId = sessionid })); } else { return(RedirectToAction("NewRequisition", "Requisition", new { sessionId = sessionid })); } } else { ViewData["userName"] = userName; ViewData["sessionId"] = sessionid; return(null); //For departments' head landing page } }