public User ToEntity(AddViewModel model) { return new User { Username = model.Username, Password = model.Password.Md5Hash(), Email = model.Email, IsAdministrator = model.IsAdministrator, Privileges = model.IsAdministrator ? new List<Privileges>() : _privilegesAssembler.ToEntities(model.Privileges) }; }
public virtual ActionResult Add(AddViewModel model) { if (!ModelState.IsValid) { return PartialView(model); } var user = Context.Users.FindByUsername(model.Username); if (user != null) { ModelState.AddModelError(Core.Infrastructure.Name.Of<AddViewModel, string>(x => x.Username), Strings.UsernameInUseMessage); return PartialView(model); } Context.Users.Save(_addAssembler.ToEntity(model)); return RedirectWithMessage(MVC.Account.ActionNames.List, Strings.UserAddedMessage); }