public ActionResult Edit(EditUserModel model) { var current = LDb.LibraryUsers.FirstOrDefault(x => x.Login == User.Identity.Name); if (ModelState.IsValid) { if (current != null) { current.FirstName = model.FirstName; current.MiddleName = model.MiddleName; current.LastName = model.LastName; current.Email = model.Email; } LDb.SaveChanges(); } return(View(current)); }
public ActionResult Registration(RegistrationModel model) { if (ModelState.IsValid) { LibraryUser libraryUser = null; using (LibraryUserContext db = new LibraryUserContext()) { libraryUser = db.LibraryUsers.FirstOrDefault(l => l.Login == model.Name); } if (libraryUser == null) { using (LibraryUserContext db = new LibraryUserContext()) { db.LibraryUsers.Add(new LibraryUser { Login = model.Name, Password = model.Password, Email = model.Email, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName }); db.SaveChanges(); libraryUser = db.LibraryUsers.Where(l => l.Login == model.Name && l.Password == model.Password).FirstOrDefault(); } if (libraryUser != null) { FormsAuthentication.SetAuthCookie(model.Name, true); return(RedirectToAction("MyPublications", "Manage")); } } } else { ModelState.AddModelError("", "Пользователь с таким логином уже существует"); } return(View(model)); }