public UserSettingsViewModel(User user) { User = user; NewUserInfo = new UserInfo(); PasswordInputModel = new PasswordInputModel(); UserInfoTypes = Enum.GetValues(typeof(UserInfoType)) .Cast<UserInfoType>() .ToSelectList(x => x.GetDescription(), x => ((int)x).ToString()); }
public User Create(User user) { var password = GeneratePassword(8); user.Password = Encrypter.Encrypt(password); _session.Save(user); // TODO send the password to the user! return user; }
public ActionResult Create(User user) { if (string.IsNullOrWhiteSpace(user.Username)) { var username = UserService.NameToUsername(user.Name); user.Username = username; } if(!_userService.IsUsernameFree(user.Username)) ModelState.AddModelError("User.Username", "Användarnamned används redan. Vänligen ange ett annat!"); if(!_userService.IsEmailFree(user.Email)) ModelState.AddModelError("User.Email", "E-postadressen används redan. Vänligen ange ett annat!"); if (!ModelState.IsValid) return Create(); _userService.Create(user); FlashSuccess("Användaren har skapats!"); return RedirectToAction("Index"); }
public CreateViewModel() { User = new User(); }
/// <summary> /// Update all replaceable properties with the props of the parameter. Rekommended only for admins /// </summary> public virtual void BigUpdate(User user) { SmallUpdate(user); Username = user.Username; Type = user.Type; }
/// <summary> /// Updates the properties the user itselves may update. /// </summary> public virtual void SmallUpdate(User user) { Name = user.Name; Email = user.Email; }
public ActionResult Settings(User user) { if (!ModelState.IsValid) return Settings(); var existingUser = _userService.Get(User.Id); if(User.IsAdmin) existingUser.BigUpdate(user); else existingUser.SmallUpdate(user); _storage.Store(SessionKeys.User, existingUser); FlashSuccess("Dina inställningar har uppdaterats!"); return RedirectToAction("Settings"); }
public ActionResult Settings(int id, User user) { if (!ModelState.IsValid) return Settings(id); var existionUser = _userService.Get(id); existionUser.BigUpdate(user); FlashSuccess("Uppgifterna har uppdaterats!"); return RedirectToAction("Index"); }
public SettingsViewModel(User user) { User = user; PasswordInputModel = new PasswordInputModel(); }