public ActionResult Register(ViewRegister data) { User nuser = ctx.Users.Where(u => u.Login == data.Login).FirstOrDefault(); if (ModelState.IsValid && nuser == null) { nuser = new User(); nuser.Name = data.Name; nuser.Email = data.Email; nuser.Login = data.Login; nuser.Country = ctx.Countries.Find(data.CountryID); nuser.City = ctx.Cities.Where(c => c.ID == data.CityID).FirstOrDefault(); nuser.Salt = SecurityHandler.GetSalt(); nuser.Password = SecurityHandler.GetHash(data.Password, nuser.Salt); nuser.AboutMe = data.About; ctx.Users.Add(nuser); ctx.SaveChangesAsync(); Session["Name"] = nuser.Name; Session["Email"] = nuser.Email; Session["Login"] = nuser.Login; Session["Country"] = nuser.Country.Name; Session["City"] = nuser.City.CityName; Session["About"] = nuser.AboutMe; return(RedirectToAction("Logged", "Home")); } else if (nuser != null) { ModelState.AddModelError("", "User already exist"); } else { ModelState.AddModelError("", "You wrong somewhere"); } ViewBag.ListCountries = new SelectList(ctx.Countries, "ID", "Name"); ViewBag.ListCities = new SelectList(ctx.Cities.Where(c => c.Country.ID == data.CountryID), "ID", "CityName"); return(PartialView(data)); }