public void Test_UserAdminCreate_ValueToModel() { var value = new UserAdminCreate { CountryId = 1, TimeZoneId = 2, Name = "test", Title = "test2", EmailAddress = "*****@*****.**", Password = "******", Signature = "test5", IsProtected = true, Status = UserStatus.Activated, Dst = UserPreferenceDaylightSavingTime.On, StartOfWeek = UserPreferenceStartOfWeek.Monday, TimeFormat = UserPreferenceTimeFormat.Extended }; var user = new User(); value.ValueToModel(user); Assert.AreEqual("test", user.Name, "Name"); Assert.AreEqual("test2", user.Title, "Title"); Assert.AreEqual("*****@*****.**", user.EmailAddress, "EmailAddress"); Assert.AreEqual("testing", user.Password, "Password"); Assert.AreEqual("test5", user.Signature, "Signature"); Assert.IsTrue(user.IsProtected, "IsProtected"); Assert.AreEqual(UserStatus.Activated, user.Status, "Status"); Assert.AreEqual(UserPreferenceDaylightSavingTime.On, value.Preference.Dst, "Dst"); Assert.AreEqual(UserPreferenceStartOfWeek.Monday, value.Preference.StartOfWeek, "StartOfWeek"); Assert.AreEqual(UserPreferenceTimeFormat.Extended, value.Preference.TimeFormat, "TimeFormat"); }
public ActionResult Create(UserAdminCreate value) { if (value == null) { throw new ArgumentNullException("value"); } var user = this.UserService.Create(); var privilege = new UserPrivilege(); if (!privilege.CanCreate(user)) { return NotAuthorized(); } value.Validate(); if (value.IsValid) { value.ValueToModel(user); this.UserService.Insert(user, value.Preference); var model = new UserAdminUpdate(user); model.SuccessMessage(Messages.UserCreated.FormatInvariant(user.Name)); return base.View(Views.Update, model); } value.CopyToModel(ModelState); return base.View(Views.Create, value); }