public virtual Tuple <int[], string[], string[]> Execute(int?filteredToYear = null, string filteredByMake = null)
        {
            int[]    years  = _manufacturerRepository.GetYears();
            string[] makes  = null;
            string[] models = null;

            if ((years != null) && (years.Length > 0))
            {
                // If the user specified a year, then look up the makes.
                // Otherwise, use the makes from the first year in the list.
                int selectedYear = -1;

                if ((filteredToYear != null) &&
                    (_manufacturerRepository.IsValidYear(filteredToYear.Value)))
                {
                    selectedYear = filteredToYear.Value;
                }

                makes = _manufacturerRepository.GetMakes(selectedYear);

                // if the user specified a year and a make, then look up the models.
                if ((makes != null) && (makes.Length > 0))
                {
                    string selectedMake = string.Empty;

                    if ((!string.IsNullOrEmpty(filteredByMake)) &&
                        (_manufacturerRepository.IsValidMake(selectedYear, filteredByMake)))
                    {
                        selectedMake = filteredByMake;
                    }

                    models = _manufacturerRepository.GetModels(selectedYear, selectedMake);
                }
            }

            if (years == null)
            {
                years = new int[] {};
            }

            if (makes == null)
            {
                makes = new string[] {};
            }

            if (models == null)
            {
                models = new string[] {};
            }

            return(new Tuple <int[], string[], string[]>(years, makes, models));
        }
        public virtual IEnumerable <ValidationResult> Execute(ICreateVehicleCommand vehicle)
        {
            bool isYearSet  = vehicle.Year.HasValue;
            bool isMakeSet  = !string.IsNullOrEmpty(vehicle.MakeName);
            bool isModelSet = !string.IsNullOrEmpty(vehicle.ModelName);

            bool isYearValid  = true;
            bool isMakeValid  = true;
            bool isModelValid = true;

            // Make requires a year
            if ((!isYearSet) && isMakeSet)
            {
                yield return(new ValidationResult("MakeName", Resources.VehicleMissingYearForMake));

                isMakeValid = false;
            }

            // Model requires a year and make
            if (isModelSet)
            {
                if (!isYearSet)
                {
                    yield return(new ValidationResult("ModelName", Resources.VehicleMissingYearForModel));

                    isModelValid = false;
                }
                else if (!isMakeSet)
                {
                    yield return(new ValidationResult("ModelName", Resources.VehicleMissingMakeForModel));

                    isModelValid = false;
                }
            }

            // Validate Year value (if not already invalid)
            if (isYearValid)
            {
                isYearValid = ((!isYearSet) || _manufacturerRepository.IsValidYear(vehicle.Year.Value));
                if (!isYearValid)
                {
                    yield return(new ValidationResult("Year", Resources.VehicleYearInvalid));
                }
            }

            // Validate Make value (if not already invalid)
            if (isMakeValid)
            {
                isMakeValid = ((!isMakeSet) ||
                               (isYearSet &&
                                _manufacturerRepository.IsValidMake(vehicle.Year.Value, vehicle.MakeName)));
                if (!isMakeValid)
                {
                    yield return(new ValidationResult("MakeName", Resources.VehicleMakeInvalid));
                }
            }

            // Validate Model value (if not already invalid)
            if (isModelValid)
            {
                isModelValid = ((!isModelSet) ||
                                (isYearSet && isMakeSet &&
                                 _manufacturerRepository.IsValidModel(vehicle.Year.Value, vehicle.MakeName,
                                                                      vehicle.ModelName)));
                if (!isModelValid)
                {
                    yield return(new ValidationResult("ModelName", Resources.VehicleModelInvalid));
                }
            }
        }