Ejemplo n.º 1
0
        public ActionResult Create(AdventureLocationModel model)
        {
            using (var businessValidator = new LocationBusiness())
            {
                IList<ValidationResult> validationErrorResults = new List<ValidationResult>();
                if (businessValidator.Validate(model.AdventureLocation, validationErrorResults))
                {
                    // Assign the adventure region to the location object.
                    model.AdventureLocation
                        .Region = _adventureRegionRepository
                            .GetAdventureRegion(model.AdventureLocation.Region.Id);

                    var locationResponse = _adventureLocationRepository.SaveAdventureLocation(model.AdventureLocation);

                    return View("Details", locationResponse);
                }

                ErrorUtility.TransformResponseErrors(ModelState, validationErrorResults);

                model.SelectableAdventureRegions = _adventureRegionRepository.GetAdventureRegions();
                model.SelectableAdventureRegions.Insert(0, Region.CreateNewRegion);

            }

            return View(model);
        }
Ejemplo n.º 2
0
        public void ValidateTest()
        {
            var locationBusiness = new LocationBusiness();
            IList<ValidationResult> validationErrorResults = new List<ValidationResult>();
            const bool NotValid = false;
            const bool Valid = true;
            bool isValidActual;

            // check validation of null location... not valid.
            AdventureLocation nullLocation = null;

            isValidActual = locationBusiness.Validate(nullLocation, null);
            Assert.AreEqual(NotValid, isValidActual, "null is not valid, null result parameter");

            // check  validation
            validationErrorResults.Clear();
            isValidActual = locationBusiness.Validate(nullLocation, validationErrorResults);
            Assert.AreEqual(NotValid, isValidActual, "null is not valid");

            // check validation of default location constructor... not valid.
            AdventureLocation defaultLocation = new AdventureLocation();

            // check validation
            validationErrorResults.Clear();
            isValidActual = locationBusiness.Validate(defaultLocation, validationErrorResults);
            Assert.AreEqual(NotValid, isValidActual, "newly constructed empty class is not valid");

            // Check validation of a seemly normal location.
            AdventureLocation validGenericLocation = new AdventureLocation(new GeoPoint { Lat = 0.0, Lon = 0.0 }, "Location");
            validGenericLocation.Region.Id = "not empty";

            // check validation
            validationErrorResults.Clear();
            isValidActual = locationBusiness.Validate(validGenericLocation, validationErrorResults);
            Assert.AreEqual(Valid, isValidActual, "Valid generic location");

            locationBusiness.Dispose();
        }
Ejemplo n.º 3
0
        public bool Validate(AdventureReview item, IList<ValidationResult> validationErrorResults)
        {
            if (null == validationErrorResults)
                validationErrorResults = new List<ValidationResult>();

            if (null == item)
                validationErrorResults.Add(new ValidationResult("A non-null object is required.", new[] { "AdventureReview" }));
            else
            {
                if (string.IsNullOrEmpty(item.AdventureName))
                    validationErrorResults.Add(new ValidationResult("A Name is required", new[] { "AdventureReviewName" }));

                if (null == item.AdventureType || string.IsNullOrEmpty(item.AdventureType.Id))
                    validationErrorResults.Add(new ValidationResult("A Adventure Type is required", new[] { "AdventureReviewAdventureType" }));

                using (var locationBusiness = new LocationBusiness())
                {
                    if (null == item.AdventureLocation)
                        validationErrorResults.Add(new ValidationResult("A Location is required", new[] { "AdventureReviewLocation" }));
                    else if (!locationBusiness.Validate(item.AdventureLocation, validationErrorResults))
                    {
                        validationErrorResults.Add(new ValidationResult("A Valid Location is required", new[] { "AdventureReviewLocation" }));
                    }
                }

                if (null == item.AdventureDuration || item.AdventureDuration <= new TimeSpan())
                    validationErrorResults.Add(new ValidationResult("A Duration Time span is required", new[] { "AdventureReviewDuriation" }));

                if (null == item.AdventureDate)
                {
                    validationErrorResults.Add(new ValidationResult("A Adventure Date is required", new[] { "AdventureReviewAdventureDate" }));
                }

            }
            return validationErrorResults.Count == 0;
        }