@@ -13,32 +13,79 @@ public class AccountCreationDateViewModel : AccountCreationViewModel, IValidatab
1313 /// <summary>
1414 /// Gets or sets the Day.
1515 /// </summary>
16- public int ? Day { get ; set ; }
16+ public string Day { get ; set ; }
17+
18+ /// <summary>
19+ /// Gets or sets the Day Field.
20+ /// </summary>
21+ public int ? DayInput { get ; set ; }
1722
1823 /// <summary>
1924 /// Gets or sets the Country.
2025 /// </summary>
21- public int ? Month { get ; set ; }
26+ public string Month { get ; set ; }
27+
28+ /// <summary>
29+ /// Gets or sets the Month input.
30+ /// </summary>
31+ public int ? MonthInput { get ; set ; }
2232
2333 /// <summary>
2434 /// Gets or sets the Year.
2535 /// </summary>
26- public int ? Year { get ; set ; }
36+ public string Year { get ; set ; }
37+
38+ /// <summary>
39+ /// Gets or sets YearInput.
40+ /// </summary>
41+ public int ? YearInput { get ; set ; }
2742
2843 /// <summary>
2944 /// Gets or sets the GetDate.
3045 /// </summary>
3146 /// <returns>DateTime.</returns>
3247 public DateTime ? GetDate ( )
3348 {
34- return ( this . Day . HasValue && this . Month . HasValue && this . Year . HasValue ) ? new DateTime ( this . Year ! . Value , this . Month ! . Value , this . Day ! . Value ) : ( DateTime ? ) null ;
49+ return ( this . DayInput . HasValue && this . MonthInput . HasValue && this . YearInput . HasValue ) ? new DateTime ( this . YearInput ! . Value , this . MonthInput ! . Value , this . DayInput ! . Value ) : ( DateTime ? ) null ;
3550 }
3651
3752 /// <inheritdoc/>
3853 public IEnumerable < ValidationResult > Validate ( ValidationContext validationContext )
3954 {
40- return DateValidator . ValidateDate ( this . Day , this . Month , this . Year , "valid start date" )
41- . ToValidationResultList ( nameof ( this . Day ) , nameof ( this . Month ) , nameof ( this . Year ) ) ;
55+ var validationResults = new List < ValidationResult > ( ) ;
56+ int parsedDay = 0 ;
57+ int parsedMonth = 0 ;
58+ int parsedYear = 0 ;
59+
60+ if ( ! string . IsNullOrWhiteSpace ( this . Day ) && ! int . TryParse ( this . Day , out parsedDay ) )
61+ {
62+ validationResults . Add ( new ValidationResult (
63+ $ "The value '{ this . Day } ' is not valid for Day.", new [ ] { nameof ( this . Day ) } ) ) ;
64+ }
65+
66+ if ( ! string . IsNullOrWhiteSpace ( this . Month ) && ! int . TryParse ( this . Month , out parsedMonth ) )
67+ {
68+ validationResults . Add ( new ValidationResult (
69+ $ "The value '{ this . Month } ' is not valid for Month.", new [ ] { nameof ( this . Month ) } ) ) ;
70+ }
71+
72+ if ( ! string . IsNullOrWhiteSpace ( this . Year ) && ! int . TryParse ( this . Year , out parsedYear ) )
73+ {
74+ validationResults . Add ( new ValidationResult (
75+ $ "The value '{ this . Year } ' is not valid for Year.", new [ ] { nameof ( this . Year ) } ) ) ;
76+ }
77+
78+ if ( validationResults . Count > 0 )
79+ {
80+ return validationResults ;
81+ }
82+
83+ this . DayInput = parsedDay ;
84+ this . MonthInput = parsedMonth ;
85+ this . YearInput = parsedYear ;
86+
87+ return DateValidator . ValidateDate ( this . DayInput , this . MonthInput , this . YearInput , "valid start date" )
88+ . ToValidationResultList ( nameof ( this . Day ) , nameof ( this . Month ) , nameof ( this . Year ) ) ;
4289 }
4390 }
4491}
0 commit comments