Addresses { get; set; }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("ExpressiveAnnotations.MvcWebSample")]
8 | [assembly: AssemblyCopyright("Copyright © Jarosław Waliszko 2014")]
9 | [assembly: AssemblyProduct("ExpressiveAnnotations.MvcWebSample")]
10 |
11 | // Setting ComVisible to false makes the types in this assembly not visible
12 | // to COM components. If you need to access a type in this assembly from
13 | // COM, set the ComVisible attribute to true on that type.
14 | [assembly: ComVisible(false)]
15 |
16 | // The following GUID is for the ID of the typelib if this project is exposed to COM
17 | [assembly: Guid("8b961e76-9cf3-46bf-bbb0-53e72c1a7e74")]
18 |
19 | // Version information for an assembly consists of the following four values:
20 | //
21 | // Major Version
22 | // Minor Version
23 | // Build Number
24 | // Revision
25 | //
26 | // You can specify all the values or you can default the Revision and Build Numbers
27 | // by using the '*' as shown below:
28 | [assembly: AssemblyVersion("1.0.0.0")]
29 | [assembly: AssemblyFileVersion("1.0.0.0")]
30 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/README.md:
--------------------------------------------------------------------------------
1 | #### Sample application illustrating model validation in ASP.NET MVC using conditional data annotations (http://expressiveannotations.net/).
2 | ---
3 | 
4 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/Views/Home/EditorTemplates/Address.cshtml:
--------------------------------------------------------------------------------
1 | @model ExpressiveAnnotations.MvcWebSample.Models.Address
2 |
3 |
4 | [AssertThat("StartsWith(Details, StreetPrefix)")]
5 | [AssertThat("Length(Trim(Details)) > Length(StreetPrefix) + 1")]
6 |
7 | [show attribute]
8 |
9 | @Html.Label(Model.Type, new { @class = "inline prefix" })
10 | @Html.TextBoxFor(model => model.Details)
11 | @Html.ValidationMessageFor(model => model.Details)
12 |
13 | @*hidden backing fields*@
14 | @Html.HiddenFor(model => model.StreetPrefix)
15 | @Html.HiddenFor(model => model.Type)
16 |
17 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/Views/Home/EditorTemplates/Contact.cshtml:
--------------------------------------------------------------------------------
1 | @model ExpressiveAnnotations.MvcWebSample.Models.Contact
2 |
3 | @{
4 | var client = "client".Equals(ViewBag.Validation);
5 | }
6 |
7 |
8 | -
9 |
10 | [RequiredIf("Parent.GoAbroad && Phone == null")]
11 | [AssertThat("IsEmail(Email)")]
12 |
13 | [show attribute]
14 |
15 | @Html.LabelFor(model => model.Email, new { @class = "inline prefix" })
16 | @Html.TextBoxFor(model => model.Email)
17 | @Html.ValidationMessageFor(model => model.Email)
18 |
19 |
20 | -
21 |
22 | [RequiredIf("Parent.GoAbroad && Email == null")]
23 | [AssertThat(@@"IsRegexMatch(Phone, '^\\d+$'), Priority = 1")]
24 | [AssertThat("Length(Phone) > 8 && Length(Phone) < 16", Priority = 2)]
25 |
26 | [show attribute]
27 |
28 | @Html.LabelFor(model => model.Phone, new { @class = "inline prefix" })
29 | @Html.TextBoxFor(model => model.Phone)
30 | @Html.ValidationMessageFor(model => model.Phone)
31 |
32 |
33 |
34 | @for (var i = 0; i < Model.Addresses.Count; i++)
35 | {
36 | -
37 | @Html.EditorFor(model => Model.Addresses[i])
38 |
39 | }
40 |
41 |
42 |
43 | @if (client)
44 | {
45 | @Html.HiddenFor(m => m.Parent.GoAbroad) @*hidden mock of GoAbroad field from Parent context*@
46 | }
47 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/Views/Shared/DisplayTemplates/ISO8601Date.cshtml:
--------------------------------------------------------------------------------
1 | @using System.Globalization
2 | @model DateTime
3 |
4 | @Html.Hidden("", Model.ToString("o", CultureInfo.InvariantCulture)) @*From MSDN: The "o" standard format specifier represents a custom date and time format
5 | string using a pattern that preserves time zone information and emits a result string
6 | that complies with ISO 8601*@
7 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/Views/Shared/DisplayTemplates/IntArray.cshtml:
--------------------------------------------------------------------------------
1 | @using Newtonsoft.Json
2 | @model int[]
3 |
4 | @Html.Hidden("", JsonConvert.SerializeObject(Model))
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/Views/Shared/_Culture.cshtml:
--------------------------------------------------------------------------------
1 | @using System.Threading
2 |
3 | @{
4 | var plLabel = "pl".Equals(Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName) ? "[polski]" : "polski";
5 | var enLabel = "en".Equals(Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName) ? "[english]" : "english";
6 | }
7 |
8 | change language to test localized information:
9 |
@plLabel
10 |
@enLabel
11 |
12 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/Views/Shared/_EAOptions.cshtml:
--------------------------------------------------------------------------------
1 | @if ("client".Equals(ViewBag.Validation))
2 | {
3 |
9 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/Views/Shared/_Indications.cshtml:
--------------------------------------------------------------------------------
1 | @if ("client".Equals(ViewBag.Validation))
2 | {
3 | var asterisksLabel = "asterisks".Equals(ViewBag.Indication) ? "[asterisks]" : "asterisks";
4 | var asterisksWithHidingLabel = "asterisks-with-hiding".Equals(ViewBag.Indication) ? "[asterisks-with-hiding]" : "asterisks-with-hiding";
5 | var noAnnotatingLabel = "no-annotating".Equals(ViewBag.Indication) ? "[no-annotating]" : "no-annotating";
6 |
7 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/Views/Shared/_Layout.cshtml:
--------------------------------------------------------------------------------
1 | @using System.Threading
2 |
3 |
4 | @{
5 | var lang = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
6 | var browser = Request.Browser.Browser.ToLowerInvariant();
7 | }
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | @*counter for ui tests*@
16 |
17 |
18 | ExpressiveAnnotations
19 | @Styles.Render("~/Content/css")
20 | @Styles.Render("~/Content/themes/base/css")
21 |
22 |
23 |
24 |
27 |
28 |
29 | @Scripts.Render("~/bundles/jquery")
30 | @Scripts.Render("~/bundles/jqueryui")
31 | @RenderSection("scripts", required: false)
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/Views/Shared/_Validation.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | var clientLabel = "client".Equals(ViewBag.Validation) ? "[client]" : "client";
3 | var serverLabel = "server".Equals(ViewBag.Validation) ? "[server]" : "server";
4 | }
5 |
10 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/Views/Web.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
40 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/Views/_ViewStart.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | Layout = "~/Views/Shared/_Layout.cshtml";
3 | }
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/Web.Debug.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
29 |
30 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/Web.Release.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
19 |
30 |
31 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/Web.config:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jwaliszko/ExpressiveAnnotations/4f04d08f633e29d2eacc483c3b1d2fb6ce62601f/src/ExpressiveAnnotations.MvcWebSample/favicon.ico
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvcWebSample/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jwaliszko/ExpressiveAnnotations/4f04d08f633e29d2eacc483c3b1d2fb6ce62601f/src/ExpressiveAnnotations.MvcWebSample/screenshot.png
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvvmDesktopSample/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvvmDesktopSample/Misc/FormatStringConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using System.Windows.Data;
4 |
5 | namespace ExpressiveAnnotations.MvvmDesktopSample.Misc
6 | {
7 | public class FormatStringConverter : IValueConverter
8 | {
9 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
10 | {
11 | var stringValue = (value as DateTime?)?.ToShortDateString() ?? value.ToString();
12 |
13 | if (parameter == null)
14 | return stringValue;
15 |
16 | var formatterString = parameter.ToString();
17 | return string.IsNullOrEmpty(formatterString)
18 | ? stringValue
19 | : string.Format(culture, formatterString, stringValue);
20 | }
21 |
22 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
23 | {
24 | throw new NotImplementedException();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/ExpressiveAnnotations.MvvmDesktopSample/Misc/NullableEnumerationExtension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel.DataAnnotations;
3 | using System.Linq;
4 | using System.Reflection;
5 | using System.Windows.Markup;
6 |
7 | namespace ExpressiveAnnotations.MvvmDesktopSample.Misc
8 | {
9 | public class NullableEnumerationExtension : MarkupExtension
10 | {
11 | private Type _enumType;
12 |
13 | public NullableEnumerationExtension(Type enumType)
14 | {
15 | EnumType = enumType ?? throw new ArgumentNullException(nameof(enumType));
16 | }
17 |
18 | private Type EnumType
19 | {
20 | get => _enumType;
21 | set
22 | {
23 | if (_enumType == value)
24 | return;
25 |
26 | var enumType = value;
27 | if (enumType.IsEnum == false)
28 | throw new ArgumentException("Type must be an Enum.");
29 |
30 | _enumType = enumType;
31 | }
32 | }
33 |
34 | public override object ProvideValue(IServiceProvider serviceProvider)
35 | {
36 | var enumValues = Enum.GetValues(EnumType);
37 | var enumItems = enumValues
38 | .Cast