public ActionResult Register(LoginAndRegisterModel register)
 {
     if (ModelState.IsValid && register.Nick.Length >= 8)
     {
         using (SurveyDbContext entities = new SurveyDbContext())
         {
             if (entities.Users.Any(X => X.Nick == register.Nick))
             {
                 return(View());
             }
             else
             {
                 User   surveyTaker = new User();
                 Random random      = new Random();
                 surveyTaker.UserId   = random.Next();
                 surveyTaker.Nick     = register.Nick;
                 surveyTaker.Password = register.Pass;
                 entities.Users.Add(surveyTaker);
                 entities.SaveChanges();
                 entities.Dispose();
                 return(RedirectToAction("Login", "Home"));
             }
         }
     }
     else
     {
         return(View());
     }
 }
Beispiel #2
0
 protected override void DisposeCore()
 {
     _dbContext?.Dispose();
 }