public ActionResult Registration(RegistrationView registrationView) { bool statusRegistration = false; string messageRegistration = string.Empty; string activationCode = null; if (ModelState.IsValid) { // Email Verification string userName = Membership.GetUserNameByEmail(registrationView.Email); if (!string.IsNullOrEmpty(userName)) { ModelState.AddModelError("Warning Email", "Sorry: Email already Exists"); return(View(registrationView)); } //Save User Data using (OeContext dbContext = new OeContext()) { var user = new User() { Username = registrationView.Username, FirstName = registrationView.FirstName, LastName = registrationView.LastName, Email = registrationView.Email, Password = registrationView.Password, ActivationCode = Guid.NewGuid().ToString(), }; activationCode = user.ActivationCode.ToString(); dbContext.Users.Add(user); dbContext.SaveChanges(); } //Verification Email VerificationEmail(registrationView.Email, activationCode); messageRegistration = "Your account has been created successfully. ^_^"; statusRegistration = true; } else { messageRegistration = "Something Wrong!"; } ViewBag.Message = messageRegistration; ViewBag.Status = statusRegistration; return(View(registrationView)); }
public ActionResult ActivationAccount(string id) { bool statusAccount = false; using (OeContext dbContext = new OeContext()) { //var usrAcc = dbContext.Users.FirstOrDefault(u => u.ActivationCode == "ecd089bc-edd3-40a7-8b73-d708be9267fb"); var userAccount = dbContext.Users.FirstOrDefault(u => u.ActivationCode.Equals(id)); if (userAccount != null) { userAccount.IsActive = true; dbContext.SaveChanges(); statusAccount = true; } else { ViewBag.Message = "Something Wrong !!"; } } ViewBag.Status = statusAccount; return(View()); }