Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult Register(RegisterModel model)
- {
- if (ModelState.IsValid)
- {
- User user = null;
- using (UserContext db = new UserContext())
- {
- user = db.Users.FirstOrDefault(u => u.Email == model.Name);
- }
- if(user == null)
- {
- using (UserContext db = new UserContext())
- {
- db.Users.Add(new User {Email = model.Name, Password = model.Password, Age = model.Age });
- db.SaveChanges();
- user = db.Users.Where(u => u.Email == model.Name && u.Password == model.Password).FirstOrDefault();
- }
- //ecli polzovatel' udachno dabavlen v bd
- if (user != null)
- {
- FormsAuthentication.SetAuthCookie(model.Name, true);
- return RedirectToAction("Index", "Home");
- }
- }
- else
- {
- ModelState.AddModelError("", "Pol'zovatel' s takim loginom uzhe sushestvuet");
- }
- }
- return View(model);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement