private void Delete(User entity) { if (context.Entry(entity).State == EntityState.Detached) { dbSet.Attach(entity); } dbSet.Remove(entity); }
void IUserRepository.Update(User entity) { dbSet.Attach(entity); context.Entry(entity).State = EntityState.Modified; }
void IUserRepository.Create(User entity) { dbSet.Add(entity); }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var confirmationToken = emailService.CreateConfirmationToken(); var user = new User() { UserName = model.UserName, DateOfBirth = model.DateOfBirth, Email = model.Email, ConfirmationToken = confirmationToken, IsConfirmed = false }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var roleBindingResult = UserManager.AddToRole(user.Id, "User"); emailService.SendConfirmationToken(model.Email, model.UserName, "http://localhost:30532" + Url.Content(Url.Action("ConfirmRegistration", "Account", new {confirmationToken = confirmationToken}))); return View("ConfirmationRequest"); } else { AddErrors(result); } } // Появление этого сообщения означает наличие ошибки; повторное отображение формы return View(model); }
private async Task SignInAsync(User user, bool isPersistent) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity); }
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { return RedirectToAction("Manage"); } if (ModelState.IsValid) { // Получение сведений о пользователе от внешнего поставщика входа var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return View("ExternalLoginFailure"); } var user = new User() { UserName = model.UserName }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await SignInAsync(user, isPersistent: false); return RedirectToLocal(returnUrl); } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return View(model); }