예제 #1
0
        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
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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 + " не поддерживается.");
            }
        }
예제 #4
0
        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;
                }
            }
        }