示例#1
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var results = new List <ValidationResult>();

            if (RefundComments != null && RefundComments.Length > 500)
            {
                results.Add(new ValidationResult(RefundDetailsViewModelResources.CommentsLengthError,
                                                 new[] { "RefundComments" }));
            }

            if (RefundAmount.ToMoneyDecimal() < 0)
            {
                results.Add(new ValidationResult(RefundDetailsViewModelResources.AmountCannotBeNegative,
                                                 new[] { "RefundAmount" }));
            }

            if (RefundAmount.ToMoneyDecimal() > Limit)
            {
                results.Add(
                    new ValidationResult(string.Format(RefundDetailsViewModelResources.AmountCannotExceedLimit, Limit),
                                         new[] { "RefundAmount" }));
            }

            if (RefundDate.AsDateTime().HasValue)
            {
                if (RefundDate.AsDateTime().Value > SystemTime.UtcNow.Date)
                {
                    results.Add(
                        new ValidationResult(RefundDetailsViewModelResources.DateNotInFuture,
                                             new[] { "RefundDate" }));
                }

                if (FirstPaymentReceivedDate.HasValue)
                {
                    if (RefundDate.AsDateTime().Value < FirstPaymentReceivedDate.Value)
                    {
                        results.Add(
                            new ValidationResult(RefundDetailsViewModelResources.DateNotBeforeFirstPayment,
                                                 new[] { "RefundDate" }));
                    }
                }
                else
                {
                    results.Add(
                        new ValidationResult(RefundDetailsViewModelResources.NoPaymentsMade,
                                             new[] { "RefundDate" }));
                }
            }

            return(results);
        }
示例#2
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var results = new List <ValidationResult>();

            if (RefundComments != null && RefundComments.Length > 500)
            {
                results.Add(new ValidationResult(RefundDetailsViewModelResources.CommentsLengthError, new[] { "Comments" }));
            }

            if (RefundAmount.ToMoneyDecimal() < 0)
            {
                results.Add(new ValidationResult(RefundDetailsViewModelResources.AmountCannotBeNegative, new[] { "RefundAmount" }));
            }

            if (RefundAmount.ToMoneyDecimal() > Limit)
            {
                results.Add(new ValidationResult(string.Format(RefundDetailsViewModelResources.AmountCannotExceedLimit, Limit), new[] { "RefundAmount" }));
            }

            return(results);
        }