Beispiel #1
0
        public IActionResult UpdateDepartmentRep(int deptRepId)
        {
            int empId = Convert.ToInt32(HttpContext.Session.GetString("id"));

            if (!(HttpContext.Session.GetString("role") == EmployeeRole.DEPTHEAD || HttpContext.Session.GetString("role") == "ActingHead"))
            {
                return(RedirectToAction(HttpContext.Session.GetString("role"), "Home"));
            }

            Department dept = null;

            if (HttpContext.Session.GetString("role") == EmployeeRole.DEPTHEAD || HttpContext.Session.GetString("role") == "ActingHead")
            {
                Employee emp = es.GetEmployeeById(empId);
                dept = emp.Department;
                Employee currentDeptRep = es.GetDeptRepByDeptId(dept.Id);

                List <Employee> employeesUnderDeptHead = es.FindAllEmployeesByDepartment(dept.Id);

                ViewData["emplist"]        = employeesUnderDeptHead;
                ViewData["currentDeptRep"] = currentDeptRep;
                ViewData["deptHead"]       = emp;
            }

            if (Request.Method.Equals("GET"))
            {
                return(View());
            }
            else
            {
                // post request to update database
                if (dept != null)
                {
                    dept.DepartmentRepId = deptRepId;
                    ds.UpdateDepartment(empId, dept);
                    Employee currentDeptRep = es.GetDeptRepByDeptId(dept.Id);
                    ViewData["currentDeptRep"] = currentDeptRep;
                }
                ems.sendchangeofdeptrepemailnotification(dept);
                return(View());
            }
        }