public void AddUser(User user) { context.Users.Add(user); SaveChanges(); }
public ActionResult SignUp(User user) { if (!ModelState.IsValid) { return View(); } User existingUser = repository.FindUserByName(user.Name); if (existingUser != null) { ModelState.AddModelError("", "Nickname is already taken. Choose another"); return View(); } else { string activationCode = Guid.NewGuid().ToString(); try { EmailSender.SendActivationCode(user.Email, activationCode); } catch (FormatException) { ModelState.AddModelError("Email", "Email format is incorrect"); return View(); } string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(user.Password, "SHA1"); user.Password = hashedPassword; user.ActivationCode = activationCode; user.IsActivated = false; user.Role = "User"; repository.AddUser(user); TempData["notice"] = string.Format("An email with activation link has been sent to {0}. Check it out", user.Email); return RedirectToAction("Index", "Home"); } }
public void UpdateUser(User user) { context.Entry(user).State = EntityState.Modified; context.SaveChanges(); }