private static void GetValidDatesFrom(TrustScreenModelBase trust, out DateTime trustStartDate, out DateTime trustFinishDate) { var parsed1 = TryToParseDate(trust.TrustStartDate, out trustStartDate); trustFinishDate = trust.TrustFinishDate.ResultDateTime.Value.Value; #region Assertions Check.That(parsed1); #endregion }
private static void TrustStartDateMustBeNoGreaterThanToday(TrustScreenModelBase trust) { if (trust.TrustStartDate.HasErrors()) { return; } DateTime trustStartDate; var parsed = TryToParseDate(trust.TrustStartDate, out trustStartDate); #region Assertions Check.That(parsed); #endregion if (trustStartDate.Date > TimeServer.Now.Date) { const string errorText = "Дата свершения доверенности должна быть не позднее сегодняшнего дня"; trust.TrustStartDate.RaiseError(errorText); } }
private static void ValidateDateFields(TrustScreenModelBase trust) { DateMustBeCorrect(trust.TrustStartDate); TrustStartDateMustBeNoGreaterThanToday(trust); switch (trust.TrustFinishDate.Type.Value) { case TrustFinishDate.TrustFinishDateType.Perpetual: { trust.TrustFinishDate.CustomTrustDate.Day.ErrorLevel = ErrorLevel.WasntChecked; trust.TrustFinishDate.CustomTrustDate.Month.ErrorLevel = ErrorLevel.WasntChecked; trust.TrustFinishDate.CustomTrustDate.Year.ErrorLevel = ErrorLevel.WasntChecked; trust.TrustFinishDate.CustomNYears.ErrorLevel = ErrorLevel.WasntChecked; break; } case TrustFinishDate.TrustFinishDateType.NYears: { trust.TrustFinishDate.CustomTrustDate.Day.ErrorLevel = ErrorLevel.WasntChecked; trust.TrustFinishDate.CustomTrustDate.Month.ErrorLevel = ErrorLevel.WasntChecked; trust.TrustFinishDate.CustomTrustDate.Year.ErrorLevel = ErrorLevel.WasntChecked; TrustStartDateMustBeLessOrEqualToTrustFinishDate(trust); break; } case TrustFinishDate.TrustFinishDateType.Custom: { DateMustBeCorrect(trust.TrustFinishDate.CustomTrustDate); TrustStartDateMustBeLessOrEqualToTrustFinishDate(trust); trust.TrustFinishDate.CustomNYears.ErrorLevel = ErrorLevel.WasntChecked; break; } default: throw new NotSupportedException("Тип " + trust.TrustFinishDate.Type.Value + " не поддерживается."); } }
private static void TrustStartDateMustBeLessOrEqualToTrustFinishDate(TrustScreenModelBase trust) { if (trust.TrustStartDate.HasErrors()) { return; } var trustFinishDateType = trust.TrustFinishDate.Type.Value; if (trustFinishDateType == TrustFinishDate.TrustFinishDateType.Custom && trust.TrustFinishDate.CustomTrustDate.HasErrors()) { return; } DateTime trustStartDate; DateTime trustFinishDate; GetValidDatesFrom(trust, out trustStartDate, out trustFinishDate); if (trustStartDate.Date > trustFinishDate.Date) { const string errorText = "Дата свершения доверенности не может быть позднее даты окончания ее действия"; trust.TrustStartDate.RaiseError(errorText); if (trustFinishDateType == TrustFinishDate.TrustFinishDateType.Custom) { trust.TrustFinishDate.CustomTrustDate.RaiseError(errorText); } else if (trustFinishDateType == TrustFinishDate.TrustFinishDateType.NYears) { var customNYears = trust.TrustFinishDate.CustomNYears; customNYears.ErrorLevel = ErrorLevel.Error; customNYears.ErrorText = errorText; } } }