public ManageRepViewModel GetManageRepViewModel(string deptId)
        {
            var query = (from x in context.AspNetUsers
                         join y in context.Department
                         on x.DepartmentId equals y.DepartmentId
                         where x.DepartmentId == deptId && x.Id != y.DepartmentHeadId && x.Id != y.DepartmentRepId
                         select x).ToList();

            //Check if any employee is already an acting department head, remove from list if so
            var modQuery = new List <AspNetUsers>(query);
            var manager  = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));

            foreach (var i in modQuery)
            {
                if (manager.IsInRole(i.Id, "Acting Department Head"))
                {
                    query.Remove(i);
                }
            }

            var users = query.Select(u => new SelectListItem
            {
                Value = u.Id,
                Text  = u.EmployeeName
            });

            ManageRepViewModel model = new ManageRepViewModel()
            {
                UserList = users
            };

            return(model);
        }
Ejemplo n.º 2
0
        public ActionResult Index(int id = 0)
        {
            if (id == 1)
            {
                ViewBag.successHandler = 1;
            }
            string userId = User.Identity.GetUserId();
            string deptId = gmService.GetDeptIdOfUser(userId);

            string empRep = gmService.GetCurrentRepName(deptId);

            ViewBag.empRep = empRep;

            ManageRepViewModel model = gmService.GetManageRepViewModel(deptId);

            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult ManageRep(ManageRepViewModel model)
        {
            ApplicationUserManager manager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
            ApplicationDbContext   context = new ApplicationDbContext();

            LogicDB database = new LogicDB();
            //Retrieve department head
            string depHeadId = User.Identity.GetUserId();
            string deptId    = gmService.GetDeptIdOfUser(depHeadId);

            //Get previous employee rep
            string oldEmpRepId = gmService.GetCurrentRepId(deptId);

            //Update to new employee rep
            gmService.UpdateDepartmentRep(model.UserId, deptId);

            //Change previous Department Rep to employee
            manager.RemoveFromRole(oldEmpRepId, "Department Representative");
            manager.AddToRole(oldEmpRepId, "Employee");
            //Assign new employee to Department Rep
            manager.RemoveFromRole(model.UserId, "Employee");
            manager.AddToRole(model.UserId, "Department Representative");
            return(RedirectToAction("Index", new { id = 1 }));
        }