public bool CreateAccount(string firstName, string lastName, string accountId) { SecurityEntities context = new SecurityEntities(); try { Account account = new Account(); account.accountID = accountId; account.firstname = firstName; account.lastname = lastName; context.Accounts.Add(account); context.SaveChanges(); return true; } catch { return false; } }
public ActionResult Register(RegisteredUser newUser) { // TAKING THE WRONG MODEL AS INPUT??? var userStore = new UserStore<IdentityUser>(); UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore) { UserLockoutEnabledByDefault = true, DefaultAccountLockoutTimeSpan = new TimeSpan(0, 10, 0), MaxFailedAccessAttemptsBeforeLockout = 3 }; var identityUser = new IdentityUser() { UserName = newUser.UserName, Email = newUser.Email }; // this threw an error, but it also worked so what gives??? IdentityResult result = manager.Create(identityUser, newUser.Password); if (result.Succeeded) { CreateTokenProvider(manager, EMAIL_CONFIRMATION); // identityUser.Id use this to create an entry in our accounts table var code = manager.GenerateEmailConfirmationToken(identityUser.Id); var callbackUrl = Url.Action("VerifiedEmail", "Accounts", new { userId = identityUser.Id, code = code }, protocol: Request.Url.Scheme); string email = "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">Confirm Registration</a>"; ViewBag.FakeConfirmation = email; UserAccountVMRepo uaRepo = new UserAccountVMRepo(); uaRepo.CreateAccount(newUser.FirstName, newUser.LastName, identityUser.Id); // CREATE WITH CONSUMER ROLE BY DEFAULT SecurityEntities context = new SecurityEntities(); AspNetUser user = context.AspNetUsers .Where(u => u.UserName == newUser.UserName).FirstOrDefault(); AspNetRole role = context.AspNetRoles .Where(r => r.Name == "consumer").FirstOrDefault(); user.AspNetRoles.Add(role); context.SaveChanges(); MailHelper mailer = new MailHelper(); string response = mailer.EmailFromArvixe( new RegisteredUser(newUser.Email, newUser.Subject = "Confirm Email", newUser.Body = email)); ViewBag.Response = response; return View("ConfirmEmail"); } return View(); }
public ActionResult AddUserToRole(string userName, string roleName) { SecurityEntities context = new SecurityEntities(); AspNetUser user = context.AspNetUsers .Where(u => u.UserName == userName).FirstOrDefault(); AspNetRole role = context.AspNetRoles .Where(r => r.Name == roleName).FirstOrDefault(); user.AspNetRoles.Add(role); context.SaveChanges(); return View(); }
public ActionResult AddRole(AspNetRole role) { SecurityEntities context = new SecurityEntities(); context.AspNetRoles.Add(role); context.SaveChanges(); return View(); }