public IActionResult RegisterAdmin(AdminRegisterViewModel model) { if (!ModelState.IsValid) { return(View()); } if (!_userLogic.CheckEmailExistance(model.Email)) { var adminEmail = User.Identity.Name; if (_userLogic.CheckAccountExistance(adminEmail, model.AdminPassword)) { _userLogic.Register(model.FirstName, model.LastName, model.Email, model.Password, 1); TempData["AdminIsCreated"] = true; return(RedirectToAction("Index")); } ModelState.AddModelError("AdminPassword", "Admin password is not correct"); return(View()); } ModelState.AddModelError("Email", "Email is already in use"); return(View()); }
public async Task <ActionResult> Register(AdminRegisterViewModel model) { if (ModelState.IsValid) { var user = new User { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _profileSuperAdminService.CreateProfileAsync(new CreateProfileRequest { Email = user.Email, FirstName = model.FirstName, LastName = model.LastName, UserId = user.Id }); await UserManager.AddToRoleAsync(user.Id, "Admin"); // For more information on how to enable account confirmation and password reset please visit https://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", "Profile", new { roleName = "Admin", Area = "SuperAdmin" })); } AddErrors(result); } // If we got this far, something failed, redisplay form ViewBag.Title = "Register a new teacher"; return(View(model)); }
public async Task <IActionResult> AdminRegister(AdminRegisterViewModel model, string returnUrl) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName }; var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { result = await userManager.AddToRoleAsync(user, "Admin"); return(Redirect(returnUrl)); //return RedirectToAction(nameof(Index)); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } return(View(model)); }
public IActionResult RegisterAdmin(string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; var model = new AdminRegisterViewModel(); return(View(model)); }
public async Task <IActionResult> AdminRegister(AdminRegisterViewModel rvm, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = rvm.Email, Email = rvm.Email }; var result = await _userManager.CreateAsync(user, rvm.Password); if (result.Succeeded) { Claim admin = new Claim(ClaimTypes.Role, "Administrator", ClaimValueTypes.String); var AddClaim = await _userManager.AddClaimAsync(user, admin); if (AddClaim.Succeeded) { await _signInManager.SignInAsync(user, isPersistent : false); return(RedirectToAction("Index", "Home")); } } //ModelState.AddModelError("Password", result.Errors.ToList()[0]); } return(View()); }
public JsonResult CreateAdmin(AdminRegisterViewModel model) { bool status = false; if (ModelState.IsValid) { try { List <Core.Domain.Users> list = _manageAdminAPIController.GetUsersByEmail(model.UserName.ToString()); Core.Domain.Users userobj = new Core.Domain.Users(); userobj.FirstName = model.FirstName; userobj.LastName = model.LastName; userobj.IndustryId = model.IndustryName; userobj.IsDeleted = false; userobj.Password = smartData.Common.CommonFunction.Encrypt(model.Password); userobj.ConfirmPassword = smartData.Common.CommonFunction.Encrypt(model.ConfirmPassword); userobj.CreatedBy = smartData.Common.SessionManager.LoggedInUser.UserID; userobj.Email = model.UserName; var addAdmin = _userService.AddUser(userobj); //int _userID = WebSecurity.GetUserId(model.UserName); //if (list.Count == 0 && _userID > 0) //{ // ((SimpleMembershipProvider)Membership.Provider).DeleteUser(model.UserName.ToString(), true); // deletes record from webpages_Membership table //} //WebSecurity.CreateUserAndAccount(model.UserName, model.Password, propertyValues: new { FirstName = model.FirstName, LastName = model.LastName, UserType = 2 }); status = true; } catch (Exception ex) { status = false; } } return(Json(new { status = status }, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> AdminRegister(AdminRegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); string role = model.Role.ToString(); if (result.Succeeded) { UserManager.AddToRole(user.Id, role); EmployeeModel row = model.MakeDataModel(); row.Account_Id = user.Id; bool success = new DatabaseAccess().InsertEmployeeRow(row, model.Role); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
//[ValidateAntiForgeryToken] //Problem 2: How to authorize only admin can assign ppl to roles //Sollution [Authorize Roles] public async Task <ActionResult> AdminRegister(AdminRegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, PhoneNumber = model.PhoneNumber }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { result = await UserManager.AddToRoleAsync(user.Id, model.RoleName); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit https://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 async Task <ActionResult> Update(AdminRegisterViewModel model) { using (var context = new AppDbContext()) { var oldUser = context.Users.FirstOrDefault(u => u.Id == model.Id); if (oldUser == null) { return(HttpNotFound()); } oldUser.PhoneNumber = model.PhoneNumber; oldUser.Email = model.Email; oldUser.AccountNumber = model.AccountNumber; var audit = new AuditTrail { Date = DateTime.Now, Title = "Updated User Datil", Detail = $"Update the details of {oldUser.AgentName}", RefUrl = Url.Action("Manage", new { oldUser.Id }) }; context.AuditTrails.Add(audit); context.SaveChanges(); ShowMessage("User updated", AlertType.Success); } return(RedirectToAction("Index")); }
public ActionResult AdminRegister(AdminRegisterViewModel adminView) { if (ModelState.IsValid) { var admin = new Admin() { FirstName = adminView.FirstName, LastName = adminView.LastName, Sex = adminView.Sex, Age = adminView.Age, PhoneNo = adminView.PhoneNo, VendorId = adminView.VendorId, Password = adminView.Password }; var user = new User() { UserId = adminView.VendorId, Password = adminView.Password }; _context.Admins.Add(admin); _context.SaveChanges(); return(View()); } else { return(View("Error")); } }
public ActionResult Register(AdminRegisterViewModel model) { if (ModelState.IsValid) { bool isValid = _db.Admins.Any(x => x.Email == model.Email); if (isValid) { ModelState.AddModelError("", "Email already exists"); return(View(model)); } Admin admin = new Admin { Name = model.Name, Email = model.Email, Password = model.Password }; _db.Admins.Add(admin); _db.SaveChanges(); return(RedirectToAction("Login", "Admin")); } return(View()); }
public IActionResult AdminRegister() { var adminVM = new AdminRegisterViewModel(); adminVM.Roles = new List <string> { "Member", "Admin" }; return(View(adminVM)); }
public async Task <ActionResult> AdminRegister(AdminRegisterViewModel model) { if (ModelState.IsValid) { if (model.ZeusAdminPassword == "Gr@de123") { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var roleStore = new RoleStore <IdentityRole>(new ApplicationDbContext()); var roleManager = new RoleManager <IdentityRole>(roleStore); if (!await roleManager.RoleExistsAsync("Admin")) { await roleManager.CreateAsync(new IdentityRole("Admin")); } await UserManager.AddToRoleAsync(user.Id, "Admin"); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); TempData["success"] = "Successfully Created."; return(View()); // For more information on how to enable account confirmation and password reset please visit https://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); } else { // If we got this far, something failed, redisplay form TempData["adminerror"] = "Admin Password did not match."; return(View(model)); } } // If we got this far, something failed, redisplay form TempData["error"] = "Sorry Something went wrong."; return(View(model)); }
public ActionResult AddAdmin() { if (Session["userId"] == null) { return(Redirect("~")); } var model = new AdminRegisterViewModel { Password = Default.Password.GetDescription() }; return(View(model)); }
public async Task <ActionResult> AdminRegister(AdminRegisterViewModel model) { try { if (ModelState.IsValid) { ApplicationDbContext db = new ApplicationDbContext(); if (db.Users.Any(k => k.UserName.ToLower() == model.UserName.ToLower())) { ModelState.AddModelError("", "UserName already exists"); return(View(model)); } ; var user = new ApplicationUser { UserName = model.UserName, Email = model.Email }; 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>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { System.Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } // If we got this far, something failed, redisplay form return(View(model)); }
public IActionResult Edit(string id) { ApplicationUser user = _userManager.FindByIdAsync(id).Result; AdminRegisterViewModel model = new AdminRegisterViewModel { Email = user.Email, FirstName = user.FirstName, LastName = user.LastName, Phone = user.PhoneNumber, NickName = user.NickName, Id = user.Id }; IList <Claim> claim = _userManager.GetClaimsAsync(user).Result; foreach (Claim item in claim) { if (item.Type == "PictureId") { model.AvatarId = Convert.ToInt32(item.Value); model.AvatarUrl = _pictureService.GetPictureUrl(pictureId: Convert.ToInt32(item.Value), defaultPictureType: PictureType.Avatar, targetSize: _storeInformationSettings.AvatarPictureSize); model.AvatarId = Convert.ToInt32(item.Value); } if (item.Type == "FacebookLink") { model.FacebookLink = item.Value; } if (item.Type == "TwitterLink") { model.TwitterLink = item.Value; } if (item.Type == "InstagramLink") { model.InstagramLink = item.Value; } } List <IdentityRole> roles = _roleManager.Roles.ToList(); PrepareCompanyList(model.IdentityRoles, true, "Rol Seçiniz"); string selectedRoles = (from ur in _context.UserRoles join u in _context.Users on ur.UserId equals u.Id join r in roles on ur.RoleId equals r.Id where ur.UserId == user.Id select r.Id).FirstOrDefault(); model.SelectedUserRoleId = selectedRoles; return(View(model)); }
/// <summary> /// create /// </summary> /// <returns></returns> public IActionResult Create() { AdminRegisterViewModel model = new AdminRegisterViewModel(); List <IdentityRole> roles = _roleManager.Roles.ToList(); PrepareCompanyList(model.IdentityRoles, true, "Kullanıcı Rol Seçiniz"); IQueryable <string> selectedRoles = (from ur in _context.UserRoles join u in _context.Users on ur.UserId equals u.Id join r in roles on ur.RoleId equals r.Id select r.Id); model.SelectedUserRoleId = selectedRoles.FirstOrDefault(); return(View(model)); }
public async Task <IActionResult> RegisterAdmin(AdminRegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (!ModelState.IsValid) { return(RedirectToAction(controllerName: $"Home", actionName: "About")); } var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { // Session Information HttpContext.Session.SetString(SessionUserName, user.UserName); _logger.LogInformation("New Admin Account Created!"); // Signin New User await _signInManager.SignInAsync(user, false); _logger.LogInformation("New User Signed In."); // Add to Role await _userManager.AddToRoleAsync(user, ModelRole); // If All Went Well- Go to Employee Home Page return(RedirectToLocal(returnUrl)); } if (result.Succeeded) { return(RedirectToAction(controllerName: $"Home", actionName: "About")); } model.Errors = AdminAccountLayer.FormatIdentityResultErrors(result); return(View(model)); }
public async Task <IActionResult> AdminRegister(AdminRegisterViewModel vm) { if (ModelState.IsValid) { User user = new User { UserName = vm.FirstName + vm.LastName, FirstName = vm.FirstName, LastName = vm.LastName, Email = vm.Email }; IdentityResult result = await userManager.CreateAsync(user, vm.Password); string role = vm.Role; if (await roleManager.FindByNameAsync(role) == null) { await roleManager.CreateAsync(new IdentityRole(role)); if (result.Succeeded) { await userManager.AddToRoleAsync(user, role); if (result.Succeeded) { return(RedirectToAction("Index", "Home")); } } else { foreach (IdentityError error in result.Errors) { ModelState.AddModelError("", error.Description); } } } else { await userManager.AddToRoleAsync(user, role); if (result.Succeeded) { return(RedirectToAction("Index", "Home")); } } } return(View(vm)); }
public async Task <IActionResult> Register(AdminRegisterViewModel model) { //later on, this register page will only be accessed by admin members var admin = new ApplicationUser { UserName = model.Email }; IdentityResult result = await _userManager.CreateAsync(admin, model.Password); if (result.Succeeded) { return(RedirectToAction("Login")); } else { return(View()); } }
public async Task <IActionResult> RegisterAdmin(AdminRegisterViewModel registerViewModel) { if (ModelState.IsValid) { User user = new User { Email = registerViewModel.Email, UserName = registerViewModel.Email, Surname = registerViewModel.Surname, Name = registerViewModel.Name, Role = "admin" }; var result = await userManager.CreateAsync(user, registerViewModel.Password); if (result.Succeeded) { await userManager.AddToRoleAsync(user, "admin"); return(RedirectToAction("AdminList", "BossAdmin")); } } return(RedirectToAction("AdminList", "BossAdmin")); }
public string Register([FromBody] AdminRegisterViewModel adminModel) { string message = ""; if (ModelState.IsValid) { //Email is already exist var isExist = IsEmailExist(adminModel.Email); if (isExist) { return("EmailExist"); } //password encoding adminModel.Password = Crypto.Hash(adminModel.Password); adminModel.ConfirmPassword = Crypto.Hash(adminModel.ConfirmPassword); Admin admin = new Admin(); admin.FirstName = adminModel.FirstName; admin.LastName = adminModel.LastName; admin.Email = adminModel.Email; admin.Password = adminModel.Password; admin.IsEmailVerified = false; //Generate Activation code admin.ActivationCode = Guid.NewGuid(); //save to database using (MyDbEntities db = new MyDbEntities()) { db.Admins.Add(admin); db.SaveChanges(); //send Email SendVerificationLinkEmail(adminModel.Email, admin.ActivationCode.ToString()); message = "For activation check your email."; return(message); } } else { return("Invalid Request"); } }
public async Task <IActionResult> AdminRegister(AdminRegisterViewModel rvm, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = rvm.Email, Email = rvm.Email }; var result = await _userManager.CreateAsync(user, rvm.Password); if (result.Succeeded) { const string issure = "www.Erik.com"; //claim list List <Claim> myClaims = new List <Claim>(); //claim users name is their email adress Claim claim1 = new Claim(ClaimTypes.Name, user.Email, ClaimValueTypes.String, issure); myClaims.Add(claim1); //claim users role Claim claim2 = new Claim(ClaimTypes.Role, "Administrator", ClaimValueTypes.String, issure); myClaims.Add(claim2); //claim for age Claim claim3 = new Claim(ClaimTypes.DateOfBirth, user.Birthday.Date.ToString(), ClaimValueTypes.Date, issure); myClaims.Add(claim3); //claim likes dogs Claim claim4 = new Claim(ClaimTypes.Email, user.Email, ClaimValueTypes.String, issure); myClaims.Add(claim4); await _userManager.AddClaimsAsync(user, myClaims); await _signInManager.SignInAsync(user, isPersistent : false); return(RedirectToAction("Index", "Home")); } //ModelState.AddModelError("Password", result.Errors.ToList()[0]); } return(View()); }
public BusinessLayerResult <Admin> RegisterAdmin(AdminRegisterViewModel data) { // Kullanıcı user kontrolü // Kullanıcı e-posta kontrolü // Kayıt işlemi // Aktivasyon e-postası gönderimi User user = repo_user.Find(x => x.mail == data.mail); BusinessLayerResult <Admin> res = new BusinessLayerResult <Admin>(); if (user != null) { if (user.mail == data.mail) { res.AddError(Entities.Messages.ErrorMessageCode.EMailAlreadyExists, "E-Posta adresi kayıtlı."); } } else { int dbResult = Insert(new Admin() { user_name = data.user_name, user_surname = data.user_surname, mail = data.mail, user_picturepath = "user_def.png", password = data.password, user_regdate = DateTime.Now, ActivateGuid = Guid.NewGuid(), notifications = new List <Notification>() }); if (dbResult > 0) { res.Result = Find(x => x.mail == data.mail); string siteUri = ConfigHelper.Get <string>("SiteRootUri"); string activateUri = $"{siteUri}/Home/AdminActivate/{res.Result.ActivateGuid}"; string body = $"Merhaba {res.Result.user_name}; !<br><br>Hesabını aktifleştirmek için <a href='{activateUri}' target='_blank'>tıklayınız</a>."; MailHelper.SendMail(body, res.Result.mail, "Online Test Platform Hesap Aktifleştirme"); } } return(res); }
public ActionResult Manage(string id) { using (var context = new AppDbContext()) { var user = context.Users.FirstOrDefault(u => u.Id == id); if (user == null) { return(HttpNotFound()); } var vm = new AdminRegisterViewModel { AgentName = user.AgentName, AccountNumber = user.AccountNumber, PhoneNumber = user.PhoneNumber, Email = user.Email, Id = user.Id }; return(View(vm)); } }
public async Task <IActionResult> AdminRegister(AdminRegisterViewModel rvm /*string returnUrl = null*/) { //ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = rvm.UserName, Email = rvm.Email, Birthday = rvm.Birthday }; var result = await _userManager.CreateAsync(user, rvm.Password); if (result.Succeeded) { //Create a list where my claims will be added to List <Claim> myClaims = new List <Claim>(); //Claim for the user's roll Claim makeAdmin = new Claim(ClaimTypes.Role, "Administrator", ClaimValueTypes.String); myClaims.Add(makeAdmin); Claim dateOfBirth = new Claim(ClaimTypes.DateOfBirth, user.Birthday.Date.ToString(), ClaimValueTypes.Date); myClaims.Add(dateOfBirth); var userIdentity = new ClaimsIdentity("Registration"); userIdentity.AddClaims(myClaims); var userPrinciple = new ClaimsPrincipal(userIdentity); User.AddIdentity(userIdentity); var addRole = await _userManager.AddClaimAsync(user, (new Claim(ClaimTypes.Role, "Administrator", ClaimValueTypes.String))); if (addRole.Succeeded) { await _signInManager.SignInAsync(user, isPersistent : false); return(RedirectToAction("AdminHome", "Home")); } } } return(View()); }
public async Task <IActionResult> Register([Bind("Username, Password, ConfirmPassword")] AdminRegisterViewModel adminViewModel) { if (ModelState.IsValid) { if (!AdminExists(adminViewModel.Username)) { Administrator admin = new Administrator { Username = adminViewModel.Username, Password = AccountsController.EncryptionPassword(adminViewModel.Password), }; _context.Administrator.Add(admin); await _context.SaveChangesAsync(); ViewData["Message"] = "Registration succeed"; return(RedirectToAction("Index", "Admin")); } } //TODO: Need to create UI for exception w/ message choose different email address throw new Exception("user email has already exist"); }
public ActionResult AddAdmin(AdminRegisterViewModel model, string returnUrl) { if (Session["userId"] == null) { return(Redirect("~")); } Users user = new Users(); AutoMapper.Mapper.Map(model, user); user.RoleId = Convert.ToInt32(Roles.Admin); user.CreatedBy = (int)Session["userId"]; try { if (new Accounts().AddUser(user)) { return(Redirect("~/Admin/Admins")); } else { return(Redirect("~/Admin/Admin/Add")); } } catch (EmailAlreadyExistsEx ex) { ModelState.AddModelError("", ex.Message); return(View(model)); } catch (PhoneAlreadyExistsEx ex) { ModelState.AddModelError("", ex.Message); return(View(model)); } catch (Exception ex) { ModelState.AddModelError("", "Unable to add Admin"); return(View(model)); } }
public async Task <ActionResult> AdminRegister(AdminRegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email, FullName = model.FullName, Surname = model.Surname }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { result = await UserManager.AddToRoleAsync(user.Id, model.RoleName); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); return(RedirectToAction("GetAllUsersWithRoles")); } AddErrors(result); } return(View(model)); }
public async Task <ActionResult> Register(AdminRegisterViewModel model) { ViewBag.Register = "current"; if (ModelState.IsValid) { //generate username MCAGNT002 var username = GenerateUsername(); var user = new ApplicationUser { AgentName = model.AgentName, AccountNumber = model.AccountNumber, Email = model.Email, PhoneNumber = model.PhoneNumber, UserName = username, ShouldChangePassword = true }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var roleResult = await UserManager.AddToRoleAsync(user.Id, model.Role); var audit = new AuditTrail { Date = DateTime.Now, Title = "Created New User", Detail = $"Created a new user with the name, {user.AgentName}", RefUrl = Url.Action("Manage", new { user.Id }) }; using (var context = new AppDbContext()) { context.AuditTrails.Add(audit); context.SaveChanges(); } return(RedirectToAction("Index", new { area = "Admin" })); } AddErrors(result); } ViewBag.Roles = new SelectList(this.RoleManager.Roles.ToList(), "Name", "Name", model.Role); // If we got this far, something failed, redisplay form return(View(model)); }