Beispiel #1
0
        public GamesByPublishingDateFilter(PublishingDatePeriod period)
        {
            switch (period)
            {
            case PublishingDatePeriod.LastWeek:
                _from = DateTime.UtcNow.AddDays(-7);
                break;

            case PublishingDatePeriod.LastMonth:
                _from = DateTime.UtcNow.AddMonths(-1);
                break;

            case PublishingDatePeriod.LastYear:
                _from = DateTime.UtcNow.AddYears(-1);
                break;

            case PublishingDatePeriod.TwoYears:
                _from = DateTime.UtcNow.AddYears(-2);
                break;

            case PublishingDatePeriod.ThreeYears:
                _from = DateTime.UtcNow.AddYears(-3);
                break;

            default:
                _from = DateTime.MinValue;
                break;
            }
        }
        public override void ValidateArgument(ArgumentExceptionDetails details)
        {
            var value = (GamesFilterAttributes)details.Value;

            if (value == null)
            {
                return;
            }

            SortingObject        sortingObject        = value.SortingObject;
            PublishingDatePeriod publishingDatePeriod = value.PublishingDatePeriod;
            decimal minPrice = value.MinPrice;
            decimal maxPrice = value.MaxPrice;

            if (!Enum.IsDefined(sortingObject.GetType(), sortingObject) ||
                !Enum.IsDefined(publishingDatePeriod.GetType(), publishingDatePeriod))
            {
                details.Message = "Undefined value of enum";
                throw new InvalidArgumentException(details);
            }

            if (minPrice < 0 || maxPrice < 0)
            {
                details.Message = "Price must be more or equal then zero";
                throw new InvalidArgumentException(details);
            }

            if (minPrice > maxPrice)
            {
                details.Message = "Min price must be less then max price";
                throw new InvalidArgumentException(details);
            }
        }