public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            RepositoryManager repositoryManager = RepositoryManagerFactory.Create();
            Cars car = repositoryManager.GetCars(CarId).Cars;

            List <ValidationResult> errors = new List <ValidationResult>();

            if (Price < (car.SalesPrice * 95) / 100)
            {
                errors.Add(new ValidationResult("Price must be > 95% of SalesPrice. That is, > " + (car.SalesPrice * 95) / 100));
            }

            if (Price > car.MSRP)
            {
                errors.Add(new ValidationResult("Price must be < MSRP " + repositoryManager.GetCars(CarId).Cars.MSRP));
            }


            if ((string.IsNullOrEmpty(Phone) && string.IsNullOrEmpty(Email)) || Email.All(c => c != '@'))
            {
                errors.Add(new ValidationResult("Must Enter Phone or valid Email"));
            }

            if (string.IsNullOrEmpty(InvoiceState))
            {
                errors.Add(new ValidationResult("Must Select state"));
            }
            if (string.IsNullOrEmpty(City))
            {
                errors.Add(new ValidationResult("Must enter city"));
            }
            if (string.IsNullOrEmpty(StreetOne))
            {
                errors.Add(new ValidationResult("Must Enter StreetOne"));
            }
            if (ZipCode == null || ZipCode.Count() != 5)
            {
                errors.Add(new ValidationResult("Zip Must be 5 digits"));
            }

            if (!int.TryParse(ZipCode, out int x))
            {
                errors.Add(new ValidationResult("Zip must be numbers"));
            }

            if (string.IsNullOrEmpty(PerchaseType))
            {
                errors.Add(new ValidationResult("Must Have PerchaseType"));
            }

            if (string.IsNullOrEmpty(InvoiceName))
            {
                errors.Add(new ValidationResult("InvoiceName Must be given a value"));
            }

            return(errors);
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            RepositoryManager repository = RepositoryManagerFactory.Create();

            List <ValidationResult> errors = new List <ValidationResult>();

            if (Year > (DateTime.Today.Year + 1) || Year < 2000)
            {
                errors.Add(new ValidationResult("Must have year between 2000 and " + (DateTime.Today.Year + 1)));
            }
            if (TypeId == 2)
            {
                if (Mileage > 1000)
                {
                    errors.Add(new ValidationResult("New Cars Cannot have more than 1000 miles"));
                }
            }

            if (TypeId == 1)
            {
                if (Mileage < 1000)
                {
                    errors.Add(new ValidationResult("Used Cars Cannot have less than 1000 miles"));
                }
            }

            if (MSRP <= 0 || MSRP < Price)
            {
                errors.Add(new ValidationResult("MSRP is Required to be greater than sales price and must be positive"));
            }
            if (Price <= 0 || MSRP < Price)
            {
                errors.Add(new ValidationResult("Price is Required to be less than MSRP and must be positive"));
            }
            if (string.IsNullOrEmpty(Discription))
            {
                errors.Add(new ValidationResult("Discription is Required"));
            }
            return(errors);
        }
Esempio n. 3
0
        public IHttpActionResult SearchNew(int?minYear, int?maxYear, int?minPrice, int?maxPrice, string make)
        {
            var repo = RepositoryManagerFactory.Create();

            try
            {
                var perameters = new ListingSearchPerameters()
                {
                    MakeModel = make,
                    MaxPrice  = maxPrice,
                    MinPrice  = minPrice,
                    MinYear   = minYear,
                    MaxYear   = maxYear
                };
                var result = repo.SearchNew(perameters);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 4
0
        public void ADOFactoryTest()
        {
            RepositoryManager repositoryManager = RepositoryManagerFactory.Create();

            Assert.IsTrue(repositoryManager.GetAllCars().Carss.Count == 6);
        }