public ActionResult EditUser(ProfileViewModel user) { if (ModelState.IsValid) { using (UsersContext context = new UsersContext()) { var user2 = context.GetUser(User.Identity.Name); if (context.GetUsers().Any(m => m.login == user.login && m.id != user.id)) { ViewBag.ErrorMessage = "Taki login już istnieje"; } else { user.id = user2.id; profileModel.EditProfile(user); } } } UserModel model = new UserModel() { PasswordModel = new LocalPasswordModel(), ProfileModel = user }; return View("Manage", model); }
public ActionResult Manage(LocalPasswordModel model) { if (ModelState.IsValid) { using (UsersContext context = new UsersContext()) { var user = context.GetUser(User.Identity.Name); if (user.password == model.OldPassword) { if (model.NewPassword == model.ConfirmPassword) { user.password = model.NewPassword; context.SaveUser(user); ViewBag.StatusMessage = "Zmiana hasła powiodła się!"; return RedirectToAction("Manage"); } else { ViewBag.ErrorMessage = "Nowe hasło i powtórzone nie są identyczne!"; } } else { ViewBag.ErrorMessage = "Stare hasło jest niepoprawne"; } } } UserModel uzytkownikModel = new UserModel() { PasswordModel = model, ProfileModel = CreateProfileModel() }; var uzytkownik = this.profileModel.GetProfile(User.Identity.Name); ViewBag.ReturnUrl = Url.Action("Manage"); return View(uzytkownikModel); }
// // GET: /Account/Manage public ActionResult Manage(ManageMessageId? message) { ViewBag.StatusMessage = message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed." : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set." : message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed." : ""; UserModel model = new UserModel() { PasswordModel = new LocalPasswordModel(), ProfileModel = CreateProfileModel() }; var uzytkownik = profileModel.GetProfile(User.Identity.Name); ViewBag.ReturnUrl = Url.Action("Manage"); return View(model); }