Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>DataAnnotationsExtensions.MVC3</id>
<version>0.6.0.0</version>
<version>0.6.0.2</version>
<authors>Scott Kirkland</authors>
<owners>Scott Kirkland</owners>
<licenseUrl>https://github.com/srkirkland/DataAnnotationsExtensions/raw/master/LICENSE.txt</licenseUrl>
<projectUrl>http://dataannotationsextensions.org</projectUrl>
<iconUrl>http://dataannotationsextensions.org/Images/CheckIcon.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Validation attributes that extend Data Annotations and provide integrated server and client side validation (using unobtrusive jquery validation).</description>
<description>Validation attributes that extend Data Annotations and provide integrated server and client side validation (using unobtrusive jquery validation).

This is a branch from the main project where rschiefer added GreaterThan and GreaterThanOrEqualTo validators.</description>
<tags>ASP.NET Validation MVC MVC3</tags>
<dependencies>
<dependency id="DataAnnotationsExtensions" version="0.6.0.0" />
<dependency id="WebActivator" version="1.1" />
<dependency id="DataAnnotationsExtensions" version="0.6.0.2" />
</dependencies>
</metadata>
<files xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<file src="../../artifacts/DataAnnotationsExtensions.ClientValidation.dll" target="lib\NETFramework40" />
<file src="Content/App_Start/RegisterClientValidationExtensions.cs.pp" target="content/App_Start" />
<file src="..\..\artifacts\DataAnnotationsExtensions.ClientValidation.dll" target="lib\NETFramework40" />
<file src="Content\App_Start\RegisterClientValidationExtensions.cs.pp" target="content\App_Start" />
<file src="..\..\..\DataAnnotationsExtensions.Web\Scripts\jquery.validate.additional-methods.js" target="content\Scripts" />
<file src="..\..\..\DataAnnotationsExtensions.Web\Scripts\jquery.validate.unobtrusive.additional-methods.js" target="content\Scripts" />
</files>
</package>
</package>
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>DataAnnotationsExtensions</id>
<version>0.6.0.0</version>
<version>0.6.0.2</version>
<authors>Scott Kirkland</authors>
<owners>Scott Kirkland</owners>
<licenseUrl>https://github.com/srkirkland/DataAnnotationsExtensions/raw/master/LICENSE.txt</licenseUrl>
<projectUrl>http://dataannotationsextensions.org</projectUrl>
<iconUrl>http://dataannotationsextensions.org/Images/CheckIcon.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Validation attributes that can be used in any .NET 4.0 project to supplement the existing Data Annotations attributes.
If you are using MVC3 and also want client validation, use the DataAnnotationsExtensions.MVC3 package.</description>
If you are using MVC3 and also want client validation, use the DataAnnotationsExtensions.MVC3 package.

This is a branch from the main project where rschiefer added GreaterThan &amp; GreaterThanOrEqualTo validators.</description>
<tags>ASP.NET Validation</tags>
</metadata>
<files xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<file src="../../artifacts/DataAnnotationsExtensions.dll" target="lib\NETFramework40" />
<file src="..\..\artifacts\DataAnnotationsExtensions.ClientValidation.dll" target="lib\NETFramework40" />
<file src="..\..\artifacts\DataAnnotationsExtensions.dll" target="lib\NETFramework40" />
</files>
</package>
</package>
Binary file not shown.
Binary file modified Build/artifacts/DataAnnotationsExtensions.NuGet.dll
Binary file not shown.
Binary file modified Build/artifacts/DataAnnotationsExtensions.dll
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using DataAnnotationsExtensions.ClientValidation.Resources;
using DataAnnotationsExtensions.ClientValidation.Rules;

namespace DataAnnotationsExtensions.ClientValidation.Adapters
{
public class GreaterThanAttributeAdapter : DataAnnotationsModelValidator<GreaterThanAttribute>
{
public GreaterThanAttributeAdapter(ModelMetadata metadata, ControllerContext context, GreaterThanAttribute attribute)
: base(metadata, context, attribute)
{
}

public override IEnumerable<ModelClientValidationRule> GetClientValidationRules()
{
Attribute.OtherPropertyDisplayName = GetOtherPropertyDisplayName();

var otherProp = FormatPropertyForClientValidation(Attribute.OtherProperty);
//We'll just use the built-in System.Web.Mvc client validation rule
return new[] { new ModelClientValidationGreaterThanRule(ErrorMessage, otherProp) };
}

private string GetOtherPropertyDisplayName()
{
if (Metadata.ContainerType != null && !String.IsNullOrEmpty(Attribute.OtherProperty))
{
var propertyMetaData = ModelMetadataProviders.Current.GetMetadataForProperty(() => Metadata.Model,
Metadata.ContainerType,
Attribute.OtherProperty);

return propertyMetaData.GetDisplayName();
}

return Attribute.OtherProperty;
}

public static string FormatPropertyForClientValidation(string property)
{
if (property == null)
{
throw new ArgumentException(ClientValidationResources.Common_NullOrEmpty, "property");
}
return "*." + property;
}
}
public class GreaterThanOrEqualToAttributeAdapter : DataAnnotationsModelValidator<GreaterThanOrEqualToAttribute>
{
public GreaterThanOrEqualToAttributeAdapter(ModelMetadata metadata, ControllerContext context, GreaterThanOrEqualToAttribute attribute)
: base(metadata, context, attribute)
{
}

public override IEnumerable<ModelClientValidationRule> GetClientValidationRules()
{
Attribute.OtherPropertyDisplayName = GetOtherPropertyDisplayName();

var otherProp = FormatPropertyForClientValidation(Attribute.OtherProperty);
//We'll just use the built-in System.Web.Mvc client validation rule
return new[] { new ModelClientValidationGreaterThanOrEqualToRule(ErrorMessage, otherProp) };
}

private string GetOtherPropertyDisplayName()
{
if (Metadata.ContainerType != null && !String.IsNullOrEmpty(Attribute.OtherProperty))
{
var propertyMetaData = ModelMetadataProviders.Current.GetMetadataForProperty(() => Metadata.Model,
Metadata.ContainerType,
Attribute.OtherProperty);

return propertyMetaData.GetDisplayName();
}

return Attribute.OtherProperty;
}

public static string FormatPropertyForClientValidation(string property)
{
if (property == null)
{
throw new ArgumentException(ClientValidationResources.Common_NullOrEmpty, "property");
}
return "*." + property;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@
<Compile Include="..\Build\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Adapters\EqualToAttributeAdapter.cs" />
<Compile Include="Adapters\YearAttributeAdapter.cs" />
<Compile Include="Adapters\CreditCardAttributeAdapter.cs" />
<Compile Include="Adapters\CuitAttributeAdapter.cs" />
<Compile Include="Adapters\DateAttributeAdapter.cs" />
<Compile Include="Adapters\DigitsAttributeAdapter.cs" />
<Compile Include="Adapters\EmailAttributeAdapter.cs" />
<Compile Include="Adapters\EqualToAttributeAdapter.cs" />
<Compile Include="Adapters\GreaterThanAttributeAdapter.cs" />
<Compile Include="Adapters\FileExtensionsAttributeAdapter.cs" />
<Compile Include="Adapters\MaxAttributeAdapter.cs" />
<Compile Include="Adapters\MinAttributeAdapter.cs" />
Expand All @@ -69,6 +70,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>ClientValidationResources.resx</DependentUpon>
</Compile>
<Compile Include="Rules\ModelClientValidationGreaterThanRule.cs" />
<Compile Include="Rules\ModelClientValidationCreditCardRule.cs" />
<Compile Include="Rules\ModelClientValidationCuitRule.cs" />
<Compile Include="Rules\ModelClientValidationDateRule.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public static void RegisterValidationExtensions()
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(UrlAttribute), typeof(UrlAttributeAdapter));
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(CreditCardAttribute), typeof(CreditCardAttributeAdapter));
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(EqualToAttribute), typeof(EqualToAttributeAdapter));
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(GreaterThanAttribute), typeof(GreaterThanAttributeAdapter));
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(GreaterThanOrEqualToAttribute), typeof(GreaterThanOrEqualToAttributeAdapter));
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(FileExtensionsAttribute), typeof(FileExtensionsAttributeAdapter));
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(NumericAttribute), typeof(NumericAttributeAdapter));
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(DigitsAttribute), typeof(DigitsAttributeAdapter));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Web.Mvc;

namespace DataAnnotationsExtensions.ClientValidation.Rules
{
public class ModelClientValidationGreaterThanRule : ModelClientValidationRule
{
public ModelClientValidationGreaterThanRule(string errorMessage, string otherProperty)
{
ErrorMessage = errorMessage;

ValidationType = "greaterthan";
ValidationParameters.Add("other", otherProperty);
}
}
public class ModelClientValidationGreaterThanOrEqualToRule : ModelClientValidationRule
{
public ModelClientValidationGreaterThanOrEqualToRule(string errorMessage, string otherProperty)
{
ErrorMessage = errorMessage;

ValidationType = "greaterthanorequalto";
ValidationParameters.Add("other", otherProperty);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<Compile Include="..\Build\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="GreaterThanEntity.cs" />
<Compile Include="YearEntity.cs" />
<Compile Include="CreditCardEntity.cs" />
<Compile Include="CuitEntity.cs" />
Expand Down
29 changes: 29 additions & 0 deletions DataAnnotationsExtensions.Core/GreaterThanEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace DataAnnotationsExtensions.Core
{
public class GreaterThanEntity
{
[Required]
[Display(Name = "LesserDisplayName")]
public DateTime Lesser { get; set; }

[GreaterThan("Lesser")]
[Required]
public DateTime Greater { get; set; }
}
public class GreaterThanOrEqualToEntity
{
[Required]
[Display(Name = "LesserDisplayName")]
public DateTime Lesser { get; set; }

[GreaterThanOrEqualTo("Lesser")]
[Required]
public DateTime Greater { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Controllers\HomeControllerTest.cs" />
<Compile Include="ValidationAttributes\GreaterThanOrEqualToAttributeTest.cs" />
<Compile Include="ValidationAttributes\GreaterThanAttributeTest.cs" />
<Compile Include="ValidationAttributes\YearAttributeTests.cs" />
<Compile Include="ValidationAttributes\CreditCardAttributeTests.cs" />
<Compile Include="ValidationAttributes\CuitAttributeTests.cs" />
Expand Down Expand Up @@ -90,6 +92,7 @@
<EmbeddedResource Include="ErrorResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>ErrorResources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
Expand Down
Loading