public ActionResult Index(string id) { //var usr = db.Users.Find(id); var user = new ApplicationUser(); user = db.Users.Find(User.Identity.GetUserId()); UserRolesHelper helper = new UserRolesHelper(db); UserProjectsHelper helper2 = new UserProjectsHelper(); if (User.IsInRole("Admin") || (User.IsInRole("Submitter"))) { return(View(db.Project.ToList())); } else if (User.IsInRole("Developer")) { return(View(user.Project.ToList())); } else if (User.IsInRole("Submitter")) { return(View(db.Project.ToList())); } else if (User.IsInRole("Project Manager")) { return(View(user.Project.ToList())); } else { return(View()); } }
public ActionResult ManageRoles(string role, string[] assignedUsers) //postback method will receive the role name given to the multiselect //list in the GET action method and it will receive a string array of the users that were selected in the multiselect list. { var helper = new UserRolesHelper(); //a new 'UserRolesHelper' object is instantiated and named 'helper'. It has all of the methods //defined in the 'UserRolesHelper' class. var dbRole = db.Roles.FirstOrDefault(r => r.Name == role); //go to the 'Roles' table in the database and find the first role where //it's 'Name' property has the same value as the 'role' parameter that was passed to this action method and assign that role //(it's 'Name' and 'Id' properties and their values) to the variable called 'dbRole'. if (dbRole == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } dbRole.Users.Clear(); //remove all of the users from the 'Users' property of 'dbRole' db.SaveChanges(); //save any changes made to the database. foreach (var user in assignedUsers ?? new string[0]) //loop over the string array 'assignedUser', which was passed as a parameter //to this acton method....LOOK INTO THE SECOND PART OF THIS LOOP STATEMENT...NOT REALLY SURE WHAT THAT IS ABOUT... { helper.AddUserToRole(user, role);//call the 'AddUserToRole' method from the 'helper' object and pass it the current user from } //the 'assignedUsers' array and the specified 'role'. return(RedirectToAction("ManageRoles", new { role }));//redirect to the 'ManageRoles' action method with a new object of the //'role' that was passed to this action method. }
// GET: Tickets public ActionResult Index() { UserRolesHelper helper = new UserRolesHelper(db); var user = User.Identity.GetUserId(); var tickets = db.Tickets.Include(t => t.Project).Include(t => t.TicketPriority).Include(t => t.TicketStatus).Include(t => t.TicketType).Include(t => t.AssignedToUser).Include(t => t.OwnerUser); if (User.IsInRole("Admin")) { return(View(tickets)); } else if (helper.IsUserInRole(user, "Project Manager")) { //var tics = user.Project.SelectMany(p => p.Ticket); var tics = db.Tickets.Where(t => t.AssignedToUserId == user).ToList(); return(View(tics)); } else if (helper.IsUserInRole(user, "Developer")) { //var tics = user.Project.SelectMany(p => p.Ticket); var tics = db.Tickets.Where(t => t.AssignedToUserId == user).ToList(); return(View(tics)); } else { //var tics = user.Project.SelectMany(p => p.Ticket); var tics = db.Tickets.Where(t => t.OwnerUserId == user).ToList(); return(View(tics)); } }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { //when a register is registered, automatically assign them the role "Submitter" so they can view a submitted ticket var helper = new UserRolesHelper(); helper.AddUserToRole(user.Id, "Submitter"); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public List <Ticket> GetUserTickets(string userId) { var user = db.Users.Find(userId); UserRolesHelper userHelper = new UserRolesHelper(db); ProjectUsersHelper projectHelper = new ProjectUsersHelper(db); var userRoles = userHelper.ListUserRoles(userId); var tickets = new List <Ticket>(); if (userRoles.Contains("Admin")) { tickets = db.Tickets.Include(t => t.Assignee).Include(t => t.Owner).Include(t => t.Project).ToList(); } else if (userRoles.Contains("Project Manager")) { tickets = user.Projects.SelectMany(p => p.Tickets).ToList(); } else if (userRoles.Contains("Developer") && userRoles.Contains("Submitter")) { tickets = db.Tickets.Where(t => t.AssigneeId == userId || t.OwnerId == userId).Include(t => t.Assignee).Include(t => t.Owner).Include(t => t.Project).ToList(); } else if (userRoles.Contains("Developer")) { //tickets where AssigneedId == userId tickets = db.Tickets.Where(t => t.AssigneeId == userId).Include(t => t.Assignee).Include(t => t.Owner).Include(t => t.Project).ToList(); } else if (userRoles.Contains("Submitter")) { //tickets where OwnerId == userID tickets = db.Tickets.Where(t => t.OwnerId == userId).Include(t => t.Assignee).Include(t => t.Owner).Include(t => t.Project).ToList(); } return(tickets); }
// GET: User Profile public ActionResult UserProfile() { ApplicationUser user = db.Users.Find(TempData["UserId"]); if (user == null) { return(RedirectToAction("Index")); } UserProfileView model = new UserProfileView(); Project project = db.Projects.Find(TempData["ProjectId"]); model.ProjectId = project.Id; UserRolesHelper helper = new UserRolesHelper(db); model.Name = user.FullName; model.Email = user.Email; model.PhoneNumber = user.PhoneNumber; model.ProjectCount = user.Projects.Count(); model.Roles = helper.ListUserRoles(user.Id); var tickets = user.Projects.SelectMany(p => p.Tickets).ToList(); model.TicketsAssigned = tickets.Where(t => t.AssigneeId == user.Id).Count(); model.TicketsSubmitted = tickets.Where(t => t.OwnerId == user.Id).Count(); model.TicketsResolved = tickets.Where(t => t.AssigneeId == user.Id).Where(t => t.Status == TicketStatus.Resolved || t.Status == TicketStatus.Closed).Count(); return(View(model)); }
// GET: Tickets/Edit/5 public ActionResult Edit(int?id) { var nHelper = new UserNotificationsHelper(); ViewBag.Notifications = nHelper.filterNotifications(User.Identity.GetUserId()); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var tHelper = new UserHelper(); Ticket ticket = tHelper.FindTicket((int)id); if (ticket == null) { return(HttpNotFound()); } TempData["Ticket"] = ticket; var rHelper = new UserRolesHelper(); ViewBag.AssignedToUserId = new SelectList(rHelper.UsersInRole("Developer"), "Id", "FirstName", ticket.AssignedToUserId); ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Name", ticket.ProjectId); ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name", ticket.TicketPriorityId); ViewBag.TicketStatusId = new SelectList(db.TicketStatuses, "Id", "Name", ticket.TicketStatusId); ViewBag.TicketTypeId = new SelectList(db.TicketTypes, "Id", "Name", ticket.TicketTypeId); return(View(ticket)); }
public ActionResult ListProjectsAndUsers() { var userList = new List <ApplicationUser>(); var helperProject = new UserProjectHelper(); var helperRole = new UserRolesHelper(); //var selectListOfRoles = db.Roles.OrderBy(r => r.Name).ToList().Select(rr => new SelectListItem { Value = rr.Name.ToString(), Text = rr.Name }).ToList(); // same as above but just string array than selected list array // var ListOfUsers = db.Users.OrderBy(r => r.LastName).ToList().Select(rr => rr.LastName.ToString()).ToList(); var ListOfProjects = db.Projects.OrderBy(p => p.Name).ToList().Select(pp => pp.Name.ToString()).ToList(); // var listOfRoles = UserDb.Roles.OrderBy(r => r.Name).ToList().Select(rr => rr.Name.ToString()); foreach (var user in db.Users) { var currentUser = new ProjectViewModels(); // Result converts Task<Ilist> to IList var ListOfProjectsForUser = helperProject.ListProjectsAssignedToUser(user.Id); currentUser.Projects = ListOfProjectsForUser; currentUser.UserId = user.Id; currentUser.UserName = user.FirstName + " " + user.LastName; currentUser.Role = helperRole.ListUserRoles(user.Id); projectInfo.Add(currentUser); } return(View("ListProjectsAndUsers", projectInfo)); }
// GET: Projects public ActionResult AllProjects() { AdminViewModel avm = new AdminViewModel(); //Populate project/pm view model List <PMViewModel> pm = new List <PMViewModel>(); foreach (var proj in db.Projects.ToList()) { PMViewModel pmvm = new PMViewModel(); pmvm.Project = proj; pmvm.PM = db.Users.Find(proj.PMID); pm.Add(pmvm); } avm.PVM = pm; //Populate tickets view model avm.Tickets = db.Tickets.ToList(); //Populate List <UserRolesViewModel> model = new List <UserRolesViewModel>(); UserRolesHelper helper = new UserRolesHelper(); var users = db.Users.ToList(); foreach (var u in users) { var urvm = new UserRolesViewModel(); urvm.User = u; urvm.Roles = helper.ListUserRoles(u.Id); model.Add(urvm); } avm.URVM = model; return(View(db.Projects.ToList())); }
public TicketController() { Db = new ApplicationDbContext(); roleHelper = new UserRolesHelper(Db); getSelectList = new GetSelectList(Db, roleHelper); }
public ActionResult AssignTicket(int?id) { UserRolesHelper helper = new UserRolesHelper(); var ticket = db.Tickets.Find(id); var users = helper.UsersInRole("Developer").ToList(); ViewBag.AssignedToUserId = new SelectList(users, "Id", "FullName"); return(View(ticket)); }
public ActionResult RolesAssigned(string userId) { var roleHelp = new UserRolesHelper(); var userAssigned = roleHelp.ListUserRoles(userId); ViewBag.Roles = new MultiSelectList(db.Roles, "Name", "Name", userAssigned); return(View(db.Users.Find(userId))); }
public ManageUserController() { roleManager = new RoleManager <IdentityRole> (new RoleStore <IdentityRole>(db)); userManager = new UserManager <ApplicationUser> (new UserStore <ApplicationUser> (db)); roleHelper = new UserRolesHelper(db); }
public ActionResult AssignPm(int?id) { UserRolesHelper helper = new UserRolesHelper(); var project = db.Projects.Find(id); var users = helper.UsersInRole("ProjectManager").ToList(); ViewBag.PMID = new SelectList(users, "Id", "FirstName", project.PMID); return(View(project)); }
public ActionResult Edit([Bind(Include = "UserId,RolesToSelect")] AdminUserViewModel admModel) { var user = db.Users.Find(admModel.UserId); var id = admModel.UserId; var allRoles = new List <string>(); UserRolesHelper helper = new UserRolesHelper(); allRoles.Add("Submitter"); allRoles.Add("Developer"); allRoles.Add("Project Manager"); allRoles.Add("Admin"); //build a list of selected roles based on the array in the model that was returned var selectedRoles = new List <string>(); for (int i = 0; i < admModel.RolesToSelect.Length; i++) { if (admModel.RolesToSelect[i].Checked == true) { selectedRoles.Add(admModel.RolesToSelect[i].RoleName); } } //if no roles have been selected, remove user from all roles if (selectedRoles == null) { foreach (var rRole in allRoles) { if (helper.IsUserInRole(admModel.UserId, rRole)) { helper.RemoveUserFromRole(admModel.UserId, rRole); } } return(RedirectToAction("Index")); } else { foreach (var sRole in selectedRoles) { if (!helper.IsUserInRole(admModel.UserId, sRole)) { helper.AddUserToRole(admModel.UserId, sRole); } } var rolesToRemove = allRoles.Except(selectedRoles); foreach (var rRole in rolesToRemove) { if (helper.IsUserInRole(admModel.UserId, rRole)) { helper.RemoveUserFromRole(admModel.UserId, rRole); } } return(RedirectToAction("Index")); } }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { // creates new user with constructor var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, DisplayName = model.DisplayName, PhoneNumber = model.PhoneNumber }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); ApplicationDbContext UserDb = new ApplicationDbContext(); var userId = UserDb.Users.Single(u => u.UserName == model.Email).Id; db.Users.FirstOrDefault(u => u.Id == userId).DisplayName = model.FirstName + " " + model.LastName; // IList<IdentityRole> userRoles = UserDb.Roles.ToList(); var helper = new UserRolesHelper(); helper.AddUserRole(userId, "Submitter"); //Lowest Priority by Default // db.Entry(User).State = EntityState.Modified; db.SaveChanges(); // BugTrackerEntities BugTrackerUser = new BugTrackerEntities(); //var BugTrackerUserInstance = new BTUser //{ // FirstName = model.FirstName, // LastName = model.LastName, // DisplayName = model.DisplayName, // AspNetUserId = UserDb.Users.FirstOrDefault(u => u.Email == model.Email).Id //}; //BugTrackerUser.BTUsers.Add(BugTrackerUserInstance); //await BugTrackerUser.SaveChangesAsync(); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
//GET: EditUserRoles public ActionResult EditUserRoles(string id) { var user = db.Users.Find(id); var helper = new UserRolesHelper(); var model = new AdminUserViewModels(); model.User = user; model.AssignedRoles = helper.ListUserRoles(id).ToArray(); model.Roles = new MultiSelectList(db.Roles, "Name", "Name", model.AssignedRoles); return(View(model)); }
public ActionResult Create() { var userRole = new UserRolesHelper(); var projectManagers = userRole.UsersInRole("Project Manager"); var projectDevelopers = userRole.UsersInRole("Developer"); var projectSubmitters = userRole.UsersInRole("Submitter"); ViewBag.projectManagers = new SelectList(projectManagers, "Id", "DisplayName"); ViewBag.projectDevelopers = new MultiSelectList(projectDevelopers, "Id", "DisplayName"); ViewBag.projectSubmitters = new MultiSelectList(projectSubmitters, "Id", "DisplayName"); return(View()); }
// GET: EditUser public ActionResult EditUser(string id) { var user = db.Users.Find(id); AdminUserViewModel AdminModel = new AdminUserViewModel(); UserRolesHelper helper = new UserRolesHelper(db); var selected = helper.ListUserRoles(id); AdminModel.Roles = new MultiSelectList(db.Roles, "Name", "Name", selected); AdminModel.Id = user.Id; AdminModel.Name = user.FullName; return(View(AdminModel)); }
public ActionResult EditUserRoles(List <UserRoleViewModel> users) { //UserRolesHelper uRoleHelper = new UserRolesHelper(); var helper = new UserRolesHelper(); var usersInAdminRole = helper.UsersInRoles("Admin"); var adminCount = usersInAdminRole.Count(); foreach (var c in users) { if (c.admin) { helper.AddUserRole(c.userId, "Admin"); } else { if (adminCount > 0) { helper.RemoveUserRole(c.userId, "Admin"); adminCount--; } } if (c.projectManager) { helper.AddUserRole(c.userId, "Project Manager"); } else { helper.RemoveUserRole(c.userId, "Project Manager"); } if (c.developer) { helper.AddUserRole(c.userId, "Developer"); } else { helper.RemoveUserRole(c.userId, "Developer"); } if (c.submitter) { helper.AddUserRole(c.userId, "Submitter"); } else { helper.RemoveUserRole(c.userId, "Submitter"); } } return(RedirectToAction("ListUsers")); }
public ActionResult EditUser(string id) { var user = db.Users.Find(id); AdminUserViewModel AdminModel = new AdminUserViewModel(); UserRolesHelper helper = new UserRolesHelper(db); var currentRoles = helper.ListUserRoles(id); var absentRoles = helper.ListAbsentUserRoles(id); AdminModel.AbsentRoles = new MultiSelectList(absentRoles); AdminModel.Roles = new MultiSelectList(currentRoles); AdminModel.User = user; return(View(AdminModel)); }
public ActionResult Create() { var Helper = new UserNotificationsHelper(); ViewBag.Notifications = Helper.filterNotifications(User.Identity.GetUserId()); var rHelper = new UserRolesHelper(); ViewBag.AssignedToUserId = new SelectList(rHelper.UsersInRole("Developer"), "Id", "FirstName"); ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Name"); ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name"); ViewBag.TicketStatusId = new SelectList(db.TicketStatuses, "Id", "Name"); ViewBag.TicketTypeId = new SelectList(db.TicketTypes, "Id", "Name"); return(View()); }
public ActionResult RolesAssigned(string userId, List <string> Roles) { var roleHelp = new UserRolesHelper(); foreach (var role in db.Roles) { var name = role.Name; roleHelp.RemoveUserFromRole(userId, name); } foreach (var role in Roles) { var list = roleHelp.AddUserToRole(userId, role); } return(RedirectToAction("ListRoles", "Admin")); }
// GET: Admin public ActionResult Index() { List <AdminUserViewModels> users = new List <AdminUserViewModels>(); UserRolesHelper helper = new UserRolesHelper(); foreach (var user in db.Users.ToList()) { var eachUser = new AdminUserViewModels(); eachUser.User = user; eachUser.AssignedRoles = helper.ListUserRoles(user.Id).ToArray(); users.Add(eachUser); } return(View(users.OrderBy(u => u.User.LastName).ToList())); }
// GET: Admin/ManageRoles/5 public ActionResult ManageRoles(string id) { var user = db.Users.Find(id); var roleUser = new UserRolesViewModel(); UserRolesHelper helper = new UserRolesHelper(); roleUser.Id = user.Id; roleUser.FirstName = user.FirstName; roleUser.LastName = user.LastName; roleUser.DisplayName = user.FirstName + " " + user.LastName; roleUser.SelectedRoles = helper.ListUserRoles(user.Id).ToArray(); roleUser.UserRoles = new MultiSelectList(db.Roles, "Name", "Name", roleUser.SelectedRoles); return(View(roleUser)); }
//GET: UserIndex public ActionResult UserIndex() { UserRolesHelper helper = new UserRolesHelper(db); List <UserRolesViewModel> model = new List <UserRolesViewModel>(); foreach (var user in db.Users.ToList()) { UserRolesViewModel UserModel = new UserRolesViewModel(); UserModel.Roles = helper.ListUserRoles(user.Id).ToList(); UserModel.User = user; model.Add(UserModel); } ; return(View(model)); }
public ActionResult AdminAddToRole(ListViewModel selectedUser, string RoleName) { var nHelper = new UserNotificationsHelper(); ViewBag.Notifications = nHelper.filterNotifications(User.Identity.GetUserId()); var Helper = new UserRolesHelper(); foreach (var id in selectedUser.SelectednonUsers) { if (id != null) { Helper.AddUserToRole(id, RoleName); Helper.AddUserToRole(id, "Project Manager"); Helper.AddUserToRole(id, "Developer"); } } List <SelectListItem> listadminUsers = new List <SelectListItem>(); List <SelectListItem> listnonadminUsers = new List <SelectListItem>(); var result1 = Helper.UsersInRole(RoleName); foreach (var user in result1) { SelectListItem selectList = new SelectListItem() { Text = user.DispalyName, Value = user.Id }; listadminUsers.Add(selectList); } var result2 = Helper.UsersNotInRole(RoleName); foreach (var user in result2) { SelectListItem selectList = new SelectListItem() { Text = user.DispalyName, Value = user.Id }; listnonadminUsers.Add(selectList); } ListViewModel adminLViewModel = new ListViewModel() { zUsers = listadminUsers, otherUsers = listnonadminUsers }; return(View("AdminAccount", adminLViewModel)); }
public ActionResult AdminIndex() { List <UserRolesViewModel> model = new List <UserRolesViewModel>(); UserRolesHelper helper = new UserRolesHelper(); var users = db.Users.ToList(); foreach (var u in users) { var urvm = new UserRolesViewModel(); urvm.User = u; urvm.Roles = helper.ListUserRoles(u.Id); model.Add(urvm); } return(View(model)); }
public List <string> ListProjectManagers(int projectId) { var projectManagers = new List <string>(); var project = db.Projects.Find(projectId); var projectUsers = project.Users.ToList(); UserRolesHelper helper = new UserRolesHelper(db); foreach (var user in projectUsers) { if (helper.IsUserInRole(user.Id, "Project Manager")) { projectManagers.Add(user.Email); } } return(projectManagers); }
public async Task <ActionResult> Register(RegisterViewModel model) { //Create DisplayName StringBuilder dn = new StringBuilder(); dn.Append(model.FirstName + " " + model.LastName); model.DisplayName = dn.ToString(); if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, DisplayName = model.DisplayName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); //Add new use to Registered User Role to limit access UserRolesHelper helper = new UserRolesHelper(db); var resultadd = helper.AddUserToRole(user.Id, "Registered User"); return(RedirectToAction("RegisterSucess", "Account")); } AddErrors(result); } LoginViewModel LoginViewModel = new LoginViewModel(); ForgotPasswordViewModel ForgotPasswordViewModel = new ForgotPasswordViewModel(); RegisterViewModel RegisterViewModel = new RegisterViewModel(); LoginGroupModel LoginGroupModel = new LoginGroupModel(); LoginGroupModel.LoginViewModel = LoginViewModel; LoginGroupModel.ForgotPasswordViewModel = ForgotPasswordViewModel; LoginGroupModel.RegisterViewModel = model; ViewBag.ErrorMsg = "Invalid Register Attempt, Please try again."; // If we got this far, something failed, redisplay form return(RedirectToAction("Login", "Account", LoginGroupModel)); }