public int SetDepartmentRep([FromBody] BriefDepartment e)//username { //Retrieve department head //string depHeadId; // var user = database.AspNetUsers.Where(x => x.Id == depHeadId).FirstOrDefault(); //Retrieve department var dept = _context.Department.Where(x => x.DepartmentId == e.DepartmentId).FirstOrDefault(); //Change department rep string oldEmpRepId = dept.DepartmentRepId; //string userId = model.UserId; dept.DepartmentRepId = e.DepartmentRepId; //Change previous Department Rep to employee ApplicationUserManager manager = HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>(); manager.RemoveFromRole(oldEmpRepId, RoleName.DepartmentRepresentative); manager.AddToRole(oldEmpRepId, RoleName.Employee); //Assign new employee to Department Rep manager.RemoveFromRole(e.DepartmentRepId, RoleName.Employee); manager.AddToRole(e.DepartmentRepId, RoleName.DepartmentRepresentative); _context.SaveChanges(); return(1); }
public BriefDepartment GetDepartments(string id)//username { GlobalClass gc = new GlobalClass(); BriefDepartment depinfo = gc.DepInfo(id); return(depinfo); }
public void assignDepRep(BriefDepartment e) { // //Retrieve department head // //string depHeadId; // // var user = database.AspNetUsers.Where(x => x.Id == depHeadId).FirstOrDefault(); // //Retrieve department // var dept = context.Department.Where(x => x.DepartmentId == e.DepartmentId).FirstOrDefault(); // //Change department rep // string oldEmpRepId = dept.DepartmentRepId; // //string userId = model.UserId; // dept.DepartmentRepId = e.DepartmentRepId; // context.SaveChanges(); // //Change previous Department Rep to employee ////manager.RemoveFromRole(oldEmpRepId, "Department Representative"); //// manager.AddToRole(oldEmpRepId, "Employee"); // //Assign new employee to Department Rep //// manager.RemoveFromRole(userId, "Employee"); // //t6manager.AddToRole(userId, "Department Representative"); }