本文整理汇总了C#中User.IsValid方法的典型用法代码示例。如果您正苦于以下问题:C# User.IsValid方法的具体用法?C# User.IsValid怎么用?C# User.IsValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User.IsValid方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public void Save(User user)
{
if (user.IsValid())
{
UserRepo.Save(user);
}
}
示例2: IsValid
public void IsValid()
{
ActiveRecordStarter.Initialize( GetConfigSource(), typeof(User) );
User user = new User();
Assert.IsFalse(user.IsValid());
user.Name = "hammett";
user.Login = "hammett";
user.Password = "123";
user.ConfirmationPassword = "123";
user.Email = "[email protected]";
Assert.IsTrue(user.IsValid());
}
示例3: IsValid
public static bool IsValid(this Tenant tenant, User user)
{
return user.IsValid() &&
AssertionConcern.IsSatisfiedBy
(
AssertionConcern.AssertNotNull(tenant.Id, "TenentId is required."),
AssertionConcern.AssertNotEmpty(tenant.Name, "The tenant name is required."),
AssertionConcern.AssertLength(tenant.Name, 1, 100, "The name must be 100 characters or less.")
);
}
示例4: InsertInvalidInfo
public static void InsertInvalidInfo()
{
log.Info("Insertando informacion invalida");
User user = new User();
//user.Username = "mario.chavez";
user.Email = "[email protected]";
if(!user.IsValid()) {
foreach (var error in user.ValidationErrorMessages) {
log.Error(String.Format("Error: {0}", error));
}
}
}
示例5: Save
public ActionResult Save(User model)
{
ExcludePropertiesInValidation("Profile.Name", "Profile.Functionalities");
if (model.IsValid(ModelState))
{
model.Password = Models.User.EncriptPassword(model.Password);
if (model.Id.Equals(0))
{
Models.User.Create(model);
}
else
{
Models.User.Update(model);
}
return new JsonResult ();
}
return View(ResultStatus.Attention);
}
示例6: ErrorMessages
public void ErrorMessages()
{
Thread.CurrentThread.CurrentCulture =
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");
ActiveRecordStarter.Initialize(GetConfigSource(), typeof(User));
User user = new User();
Type type = user.GetType();
PropertyInfo info;
ArrayList propertyMessages;
Assert.IsFalse(user.IsValid());
Assert.AreEqual(5, user.ValidationErrorMessages.Length);
Assert.AreEqual("This is a required field", user.ValidationErrorMessages[0]);
Assert.AreEqual("This is a required field", user.ValidationErrorMessages[1]);
Assert.AreEqual("This is a required field", user.ValidationErrorMessages[2]);
Assert.AreEqual("This is a required field", user.ValidationErrorMessages[3]);
Assert.AreEqual("This is a required field", user.ValidationErrorMessages[4]);
Assert.AreEqual(5, user.PropertiesValidationErrorMessages.Count);
info = type.GetProperty("Login");
Assert.IsTrue(user.PropertiesValidationErrorMessages.Contains(info));
propertyMessages = (ArrayList)user.PropertiesValidationErrorMessages[info];
Assert.AreEqual(1, propertyMessages.Count);
Assert.AreEqual("This is a required field", propertyMessages[0]);
info = type.GetProperty("Name");
Assert.IsTrue(user.PropertiesValidationErrorMessages.Contains(info));
propertyMessages = (ArrayList)user.PropertiesValidationErrorMessages[info];
Assert.AreEqual(1, propertyMessages.Count);
Assert.AreEqual("This is a required field", propertyMessages[0]);
info = type.GetProperty("Email");
Assert.IsTrue(user.PropertiesValidationErrorMessages.Contains(info));
propertyMessages = (ArrayList)user.PropertiesValidationErrorMessages[info];
Assert.AreEqual(1, propertyMessages.Count);
Assert.AreEqual("This is a required field", propertyMessages[0]);
info = type.GetProperty("Password");
Assert.IsTrue(user.PropertiesValidationErrorMessages.Contains(info));
propertyMessages = (ArrayList)user.PropertiesValidationErrorMessages[info];
Assert.AreEqual(1, propertyMessages.Count);
Assert.AreEqual("This is a required field", propertyMessages[0]);
info = type.GetProperty("ConfirmationPassword");
Assert.IsTrue(user.PropertiesValidationErrorMessages.Contains(info));
propertyMessages = (ArrayList)user.PropertiesValidationErrorMessages[info];
Assert.AreEqual(1, propertyMessages.Count);
Assert.AreEqual("This is a required field", propertyMessages[0]);
user.Name = "hammett";
user.Login = "hammett";
user.Email = "[email protected]";
user.Password = "123x";
user.ConfirmationPassword = "123";
Assert.IsFalse(user.IsValid());
Assert.AreEqual(1, user.ValidationErrorMessages.Length);
Assert.AreEqual("Fields do not match", user.ValidationErrorMessages[0]);
info = type.GetProperty("Password");
Assert.IsTrue(user.PropertiesValidationErrorMessages.Contains(info));
propertyMessages = (ArrayList)user.PropertiesValidationErrorMessages[info];
Assert.AreEqual(1, propertyMessages.Count);
Assert.AreEqual("Fields do not match", propertyMessages[0]);
user.Password = "123";
Assert.IsTrue(user.IsValid());
Assert.AreEqual(0, user.ValidationErrorMessages.Length);
}
示例7: Add
/// <summary>
/// Add user to repository
/// </summary>
/// <param name="user"></param>
public int Add(User user)
{
rwls.EnterWriteLock();
try
{
ts.TraceInformation($"Add user request in MasterService at {DateTime.Now} in {AppDomain.CurrentDomain.FriendlyName}");
if (ReferenceEquals(null, user))
{
ts.TraceInformation($"Argument null exception in add user request at master in {AppDomain.CurrentDomain.FriendlyName}");
throw new ArgumentNullException();
}
if (!user.IsValid())
{
ts.TraceInformation($"Validation exception in add user request at master in {AppDomain.CurrentDomain.FriendlyName}");
throw new ArgumentException("Validation error : Incorrect user entity");
}
_id = StorageType.Add(user);
OnModify(new Message("UserAdded", _id, user, null));
return _id;
}
finally
{
rwls.ExitWriteLock();
}
}