public ActionResult ChangeRoleOfUserInGroup([Bind(Include = "SelectedUser, SelectedRole, SelectedOldRole")] UserChangeRoleViewModel changedRole) { if (ModelState.IsValid) { //ViewBag.Name = changedRole.Name; ApplicationUser user = new ApplicationUser(); user.UserName = changedRole.SelectedUser; //var account = new AccountController(); //var role = System.Web.Security.Roles.GetRolesForUser().Single(); //var role = account.UserManager.GetRoles(changedRole.SelectedUser.ToString()); //repo.RemoveUserRole(user.UserName, changedRole.SelectedOldRoles); if (changedRole.SelectedOldRole != null) { repo.RemoveUserRole(changedRole.SelectedUser, changedRole.SelectedOldRole); } repo.AddUserRole(changedRole.SelectedUser, changedRole.SelectedRole); return RedirectToAction("Users"); } //ViewBag.DepartmentId = new SelectList(repo.GetGroupsByDepartmentId, "Id", "Name", group.DepartmentId); return View(changedRole); }
public ActionResult InviteUserToInterview(string mail) { if (mail == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } ApplicationUser user = new ApplicationUser(); var uId = repo.ApplicationUsers().Single(m => m.Email == mail).Id; user = repo.GetSpecificUser(uId); if (user == null) { return HttpNotFound(); } //SKapa VM instans UserViewModel inviteVM = new UserViewModel(); //Bind detta ID till Viewmodell ViewBag.Id = user.Id; inviteVM.Email = repo.ApplicationUsers().Single(m => m.Email == mail).Email; //Returna View med VM return View(inviteVM); }
public ActionResult InviteUserForGroup(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Group group = repo.GetSpecificGroup(id); ApplicationUser groupUser = new ApplicationUser(); if (group == null) { return HttpNotFound(); } //SKapa VM instans UserInviteViewModel inviteVM = new UserInviteViewModel(); //Bind detta ID till Viewmodell inviteVM.Id = group.Id; inviteVM.Name = group.Name; inviteVM.Users = repo.ApplicationUsers().Where(g => g.Id == g.Id ).Select(u => new SelectListItem { Text = u.UserName, Value = u.Id }); ViewBag.Name = group.Name; //Returna View med VM return View(inviteVM); }
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { return RedirectToAction("Index", "Manage"); } if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return View("ExternalLoginFailure"); } var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); return RedirectToLocal(returnUrl); } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return View(model); }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, Name = model.Name, Surname = model.Surname, }; 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>"); if (!UserManager.IsInRole(user.Id,"Job Searcher" )) { UserManager.AddToRole(user.Id, "Job Searcher"); } return RedirectToAction("Index", "Home"); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }
public void Delete(ApplicationUser Entity) { db.user.Remove(Entity); db.SaveChanges(); }