public IDictionary<string, string> GetAdDataConsistencyErrors(AdvancedAdCreateModel model)
        {
            IDictionary<string, string> errors = new Dictionary<string, string>();

            // Check base ad data consistency
            GetBaseAdDataConsistencyErrors(model, errors);

            // Check user data consistency
            GetUserDataConsistencyErrors(model, errors);

            if (model.Type == AdTypeEnum.Undefined)
                return errors;

            // Check specifyc ad data consistency
            switch (model.Type)
            {
                case AdTypeEnum.CarAd:
                    GetCarAdDataConsistencyErrors(model, errors);
                    break;

                case AdTypeEnum.MotoAd:
                    GetMotoAdDataConsistencyErrors(model, errors);
                    break;

                case AdTypeEnum.OtherVehiculeAd:
                    GetOtherVehicleAdDataConsistencyErrors(model, errors);
                    break;

                case AdTypeEnum.VehiculeAd:
                    GetVehicleAdDataConsistencyErrors(model, errors);
                    break;

                case AdTypeEnum.MotorBoatAd:
                    GetMotorBoatAdDataConsistencyErrors(model, errors);
                    break;

                case AdTypeEnum.SailingBoatAd:
                    GetSailingBoatAdDataConsistencyErrors(model, errors);
                    break;

                case AdTypeEnum.MotorBoatEngineAd:
                    GetMotorBoatEngineAdDataConsistencyErrors(model, errors);
                    break;

                case AdTypeEnum.WaterSportAd:
                    GetWaterSportAdDataConsistencyErrors(model, errors);
                    break;

                case AdTypeEnum.RealEstateAd:
                    GetRealEstateAdDataConsistencyErrors(model, errors);
                    break;
                default:
                    break;
            }

            return errors;
        }
Esempio n. 2
0
        public PartialViewResult AddParamters(int categoryId)
        {
            Category selectedCategory = _categoryServices.GetCategoryById(categoryId);
            FillViewLists(selectedCategory.Type);
            AdvancedAdCreateModel model = new AdvancedAdCreateModel();
            switch (selectedCategory.Type)
            {
                case AdTypeEnum.CarAd:
                    model.Type = AdTypeEnum.CarAd;
                    return PartialView("Shared/Create/_CarAdCreate", model);

                case AdTypeEnum.MotoAd:
                    model.Type = AdTypeEnum.MotoAd;
                    return PartialView("Shared/Create/_MotoAdCreate", model);

                case AdTypeEnum.VehiculeAd:
                    model.Type = AdTypeEnum.VehiculeAd;
                    return PartialView("Shared/Create/_VehicleAdCreate", model);

                case AdTypeEnum.OtherVehiculeAd:
                    model.Type = AdTypeEnum.OtherVehiculeAd;
                    return PartialView("Shared/Create/_OtherVehicleAdCreate", model);

                case AdTypeEnum.MotorBoatAd:
                    model.Type = AdTypeEnum.MotorBoatAd;
                    return PartialView("Shared/Create/_MotorBoatAdCreate", model);

                case AdTypeEnum.SailingBoatAd:
                    model.Type = AdTypeEnum.SailingBoatAd;
                    return PartialView("Shared/Create/_SailingBoatAdCreate", model);

                case AdTypeEnum.MotorBoatEngineAd:
                    model.Type = AdTypeEnum.MotorBoatEngineAd;
                    return PartialView("Shared/Create/_MotorBoatEngineAdCreate", model);

                case AdTypeEnum.WaterSportAd:
                    model.Type = AdTypeEnum.WaterSportAd;
                    return PartialView("Shared/Create/_WaterSportAdCreate", model);

                case AdTypeEnum.RealEstateAd:
                    model.Type = AdTypeEnum.RealEstateAd;
                    return PartialView("Shared/Create/_realEstateAdCreate", model);
            }
            return null;
        }
        public IDictionary<string, string> GetBaseAdDataConsistencyErrors(AdvancedAdCreateModel model, IDictionary<string, string> errors)
        {
            if (String.IsNullOrEmpty(model.Title))
                errors.Add("Title", "Veuillez donner un titre à votre annonce.");

            if (String.IsNullOrEmpty(model.Body))
                errors.Add("Body", "Veuillez rédiger un texte d'annonce.");

            if (model.Price < 0)
                errors.Add("Price", "Veuillez saisir un prix positif.");

            if (!String.IsNullOrEmpty(model.Telephone) && !_phoneRegex.IsMatch(model.Telephone))
                errors.Add("Telephone", "Telephone invalide.");

            if (model.SelectedCityId == null)
                errors.Add("SelectedCityId", "Veuillez sélectionner une ville.");

            if (model.SelectedCategoryId == null)
                errors.Add("SelectedCategoryId", "Veuillez séléctionner une catégorie.");

            return errors;
        }
        public void GetAdDataConsistencyErrors_Ad_NoCity_ReturnsDictionaryWithCityError()
        {
            // Given
            AdDataConsistencyServices service = new AdDataConsistencyServices();
            AdvancedAdCreateModel model = new AdvancedAdCreateModel()
            {
                Body = "My Body",
                Title = "My Title",
                SelectedCategoryId = 1,
                Name = "My Name",
                Email = "*****@*****.**",
                Password = "******",
                PasswordConfirm = "Password"
            };

            // When
            IDictionary<string, string> actual = service.GetAdDataConsistencyErrors(model);

            // Then
            Assert.AreEqual(1, actual.Count);
            Assert.IsTrue(actual.Keys.Contains("SelectedCityId"));
        }
        public void GetAdDataConsistencyErrors_RealEstateAd_NoSurfaceArea_ReturnsDictionaryWithSurfaceAreaError()
        {
            // Given
            AdDataConsistencyServices service = new AdDataConsistencyServices();
            AdvancedAdCreateModel model = new AdvancedAdCreateModel()
            {
                Body = "My Body",
                Title = "My Title",
                SelectedCityId = 1,
                SelectedCategoryId = 1,
                Name = "My Name",
                Email = "*****@*****.**",
                RoomNb = 5,
                SelectedRealEstateTypeId = 1,
                IsFurnished = true,
                Type = AdTypeEnum.RealEstateAd,
                Password = "******",
                PasswordConfirm = "Password"
            };

            // When
            IDictionary<string, string> actual = service.GetAdDataConsistencyErrors(model);

            // Then
            Assert.AreEqual(1, actual.Count);
            Assert.IsTrue(actual.Keys.Contains("SurfaceArea"));
        }
        public void GetAdDataConsistencyErrors_Ad_NoError_ReturnsEmptyDictionary()
        {
            // Given
            AdDataConsistencyServices service = new AdDataConsistencyServices();
            AdvancedAdCreateModel model = new AdvancedAdCreateModel() {
                Body = "My Body",
                Title = "My Title",
                SelectedCityId = 1,
                SelectedCategoryId = 1,
                Name = "My Name",
                Email = "*****@*****.**",
                Password = "******",
                PasswordConfirm = "Password"
            };

            //When
            IDictionary<string, string> errors = service.GetAdDataConsistencyErrors(model);

            //Then
            Assert.AreEqual(0, errors.Count);
        }
        public void GetAdDataConsistencyErrors_OtherVehicleAd__NoKiliometer_ReturnsDictionaryWithKmError()
        {
            // Given
            AdDataConsistencyServices service = new AdDataConsistencyServices();
            AdvancedAdCreateModel model = new AdvancedAdCreateModel()
            {
                Body = "My Body",
                Title = "My Title",
                SelectedCityId = 1,
                SelectedCategoryId = 1,
                Name = "My Name",
                Email = "*****@*****.**",
                SelectedYearId = 2008,
                SelectedFuelId = 1,
                Type = AdTypeEnum.OtherVehiculeAd,
                Password = "******",
                PasswordConfirm = "Password"
            };
            // When
            IDictionary<string, string> actual = service.GetAdDataConsistencyErrors(model);

            // Then
            Assert.AreEqual(1, actual.Count);
            Assert.IsTrue(actual.Keys.Contains("Km"));
        }
Esempio n. 8
0
        public ActionResult Create(AdvancedAdCreateModel model)
        {
            IDictionary<string, string> errors = _adConsistencyServices.GetAdDataConsistencyErrors(model);

            foreach (string key in errors.Keys)
                ModelState.AddModelError(key, errors[key]);

            // This line validates the captcha code and creates a ModelError if not valid
            this.IsCaptchaValid("Code invalide");

            if (ModelState.IsValid)
            {
                BaseAd newAd = _adServices.GetAdFromAdCreateModel(model);
                _adServices.AddAd(newAd);
                return View("Created");
            }

            FillViewLists(model.Type);
            return View(model);
        }
        public void GetAdDataConsistencyErrors_MotoAd_NegativeKilometer_ReturnsDictionaryWithKilometerError()
        {
            // Given
            AdDataConsistencyServices service = new AdDataConsistencyServices();
            AdvancedAdCreateModel model = new AdvancedAdCreateModel()
            {
                Body = "My Body",
                Title = "My Title",
                SelectedCityId = 1,
                SelectedCategoryId = 1,
                Name = "My Name",
                Email = "*****@*****.**",
                SelectedMotoBrandId = 1,
                SelectedYearId = 2008,
                EngineSize = 600,
                Km = -55000,
                Type = AdTypeEnum.MotoAd,
                Password = "******",
                PasswordConfirm = "Password"
            };

            // When
            IDictionary<string, string> actual = service.GetAdDataConsistencyErrors(model);

            // Then
            Assert.AreEqual(1, actual.Count);
            Assert.IsTrue(actual.Keys.Contains("Km"));
        }
 public IDictionary<string, string> GetUserDataConsistencyErrors(AdvancedAdCreateModel model, IDictionary<string, string> errors)
 {
     if (String.IsNullOrEmpty(model.Name))
             errors.Add("Name", "Veuillez saisir un nom.");
     if (String.IsNullOrEmpty(model.Email))
             errors.Add("Email", "Veuillez insérer une adresse email.");
     else
         if (!_emailRegex.IsMatch(model.Email))
             errors.Add("Email", "Email invalide.");
     if (String.IsNullOrEmpty(model.Password))
         errors.Add("Password", "Veuillez saisir votre mot de passe.");
     else
     {
         if (String.IsNullOrEmpty(model.PasswordConfirm))
             errors.Add("PasswordConfirm", "Veuillez confirmer le mot de passe.");
         else
             if (!model.Password.Equals(model.PasswordConfirm))
                 errors.Add("PasswordConfirm", "Les mots de passe saisis sont différents.");
     }
     return errors;
 }
        public IDictionary<string, string> GetSailingBoatAdDataConsistencyErrors(AdvancedAdCreateModel model, IDictionary<string, string> errors)
        {
            if (model.SelectedHullTypeId == null)
                errors.Add("SelectedHullTypeId", "Veuillez sélectionner une coque.");

            if (model.SelectedSailingBoatTypeId == null)
                errors.Add("SelectedSailingBoatTypeId", "Veuillez sélectionner un matériaux.");

            if (model.SelectedYearId == null)
                errors.Add("SelectedYearId", "Veuillez sélectionner une annee-modele.");

            if (model.Length == null)
                errors.Add("Length", "Veuillez saisir une longueur.");
            else
                if(model.Length.Value<0)
                    errors.Add("Length", "Longueur incorrecte.");

            return errors;
        }
        public IDictionary<string, string> GetRealEstateAdDataConsistencyErrors(AdvancedAdCreateModel model, IDictionary<string, string> errors)
        {
            if (model.SelectedRealEstateTypeId == null)
                errors.Add("SelectedRealEstateTypeId", "Veuillez sélectionner un type de bien.");

            if (model.RoomNb == null)
                errors.Add("RoomNb", "Veuillez sélectionner un nombre de pieces.");
            else
                if(model.RoomNb.Value<0)
                    errors.Add("RoomNb", "Nombre de pieces incorrecte.");

            if (model.SurfaceArea == null)
                errors.Add("SurfaceArea", "Veuillez saisir une superficie.");
            else
                if (model.SurfaceArea.Value<0)
                    errors.Add("SurfaceArea", "Superficie incorrecte.");

            if (model.IsFurnished == null)
                errors.Add("IsFurnished", "Veuillez selectionner une option.");

            return errors;
        }
        public IDictionary<string, string> GetMotorBoatEngineAdDataConsistencyErrors(AdvancedAdCreateModel model, IDictionary<string, string> errors)
        {
            if (model.SelectedMotorBoatEngineTypeId == null)
                errors.Add("SelectedMotorBoatEngineTypeId", "Veuillez sélectionner un type de moteur.");

            if (model.SelectedYearId == null)
                errors.Add("SelectedYearId", "Veuillez sélectionner une annee-modele.");

            if (model.Hp == null)
                errors.Add("Hp", "Veuillez saisir une puissance.");
            else
                if (model.Hp.Value < 0)
                    errors.Add("Hp", "Puissance incorrecte.");

            return errors;
        }
        public IDictionary<string, string> GetMotoAdDataConsistencyErrors(AdvancedAdCreateModel model, IDictionary<string, string> errors)
        {
            if (model.Km == null)
                errors.Add("Km", "Veuillez séléctionner un kilométrage.");
            else
                if (model.Km.Value < 0)
                    errors.Add("Km", "Kilométrage incorrecte.");

            if (model.SelectedYearId == null)
                errors.Add("SelectedYearId", "Veuillez sélectionner une annee-modele.");

            if (model.EngineSize == null)
                errors.Add("EngineSize", "Veuillez sélectionner une cylindrée.");
            else
                if(model.EngineSize.Value<0)
                    errors.Add("EngineSize", "Cylindrée incorrecte.");

            if (model.SelectedMotoBrandId == null)
                errors.Add("SelectedMotoBrandId", "Veuillez sélectionner une marque.");

            return errors;
        }
        public void GetAdDataConsistencyErrors_SailingBoatAdAd_NegativeLength_ReturnsDictionaryWithoLengthErrors()
        {
            // Given
            AdDataConsistencyServices service = new AdDataConsistencyServices();
            AdvancedAdCreateModel model = new AdvancedAdCreateModel()
            {
                Body = "My Body",
                Title = "My Title",
                SelectedCityId = 1,
                SelectedCategoryId = 1,
                Name = "My Name",
                Email = "*****@*****.**",
                SelectedSailingBoatTypeId = 1,
                Length = -5,
                SelectedYearId = 2011,
                SelectedHullTypeId = 1,
                Type = AdTypeEnum.SailingBoatAd,
                Password = "******",
                PasswordConfirm = "Password"
            };

            // When
            IDictionary<string, string> actual = service.GetAdDataConsistencyErrors(model);

            // Then
            Assert.AreEqual(1, actual.Count);
            Assert.IsTrue(actual.Keys.Contains("Length"));
        }
        public void GetAdDataConsistencyErrors_CarAd_MissingFuel_ReturnsDictionaryWithFuelError()
        {
            // Given
            AdDataConsistencyServices service = new AdDataConsistencyServices();
            AdvancedAdCreateModel model = new AdvancedAdCreateModel()
            {
                Body = "My Body",
                Title = "My Title",
                SelectedCityId = 1,
                SelectedCategoryId = 1,
                Name = "My Name",
                Email = "*****@*****.**",
                SelectedCarBrandId = 1,
                SelectedYearId = 2008,
                Km = 55000,
                Type = AdTypeEnum.CarAd,
                Password = "******",
                PasswordConfirm = "Password"
            };

            // When
            IDictionary<string, string> actual = service.GetAdDataConsistencyErrors(model);

            // Then
            Assert.AreEqual(1, actual.Count);
            Assert.IsTrue(actual.Keys.Contains("SelectedFuelId"));
        }
        public IDictionary<string, string> GetVehicleAdDataConsistencyErrors(AdvancedAdCreateModel model, IDictionary<string, string> errors)
        {
            if (model.Km == null)
                errors.Add("Km", "Veuillez séléctionner un kilométrage.");
            else
                if (model.Km.Value < 0)
                    errors.Add("Km", "Kilométrage incorrecte.");
            if (model.SelectedYearId == null)
                errors.Add("SelectedYearId", "Veuillez sélectionner une annee-modele.");

            return errors;
        }
        public void GetAdDataConsistencyErrors_MotorBoatAdAd_NoError_ReturnsEmptyDictionary()
        {
            // Given
            AdDataConsistencyServices service = new AdDataConsistencyServices();
            AdvancedAdCreateModel model = new AdvancedAdCreateModel()
            {
                Body = "My Body",
                Title = "My Title",
                SelectedCityId = 1,
                SelectedCategoryId = 1,
                Name = "My Name",
                Email = "*****@*****.**",
                SelectedMotorBoatTypeId = 1,
                Length = 5,
                SelectedYearId = 2011,
                SelectedMotorTypeId = 1,
                Hp=200,
                Type = AdTypeEnum.MotorBoatAd,
                Password = "******",
                PasswordConfirm = "Password"
            };

            // When
            IDictionary<string, string> actual = service.GetAdDataConsistencyErrors(model);

            // Then
            Assert.AreEqual(0, actual.Count);
        }
        public IDictionary<string, string> GetWaterSportAdDataConsistencyErrors(AdvancedAdCreateModel model, IDictionary<string, string> errors)
        {
            if (model.SelectedWaterSportTypeId == null)
                errors.Add("SelectedWaterSportTypeId", "Veuillez sélectionner une discipline.");

            return errors;
        }
        public void GetAdDataConsistencyErrors_MotorBoatEngineAdAd_NoSelectedMotorBoatEngineTypeId_ReturnsDictionaryWithSelectedMotorBoatEngineTypeIdError()
        {
            // Given
            AdDataConsistencyServices service = new AdDataConsistencyServices();
            AdvancedAdCreateModel model = new AdvancedAdCreateModel()
            {
                Body = "My Body",
                Title = "My Title",
                SelectedCityId = 1,
                SelectedCategoryId = 1,
                Name = "My Name",
                Email = "*****@*****.**",
                Hp = 500,
                SelectedYearId = 2011,
                Type = AdTypeEnum.MotorBoatEngineAd,
                Password = "******",
                PasswordConfirm = "Password"
            };

            // When
            IDictionary<string, string> actual = service.GetAdDataConsistencyErrors(model);

            // Then
            Assert.AreEqual(1, actual.Count);
            Assert.IsTrue(actual.Keys.Contains("SelectedMotorBoatEngineTypeId"));
        }
Esempio n. 21
0
 public ActionResult Create()
 {
     AdvancedAdCreateModel model = new AdvancedAdCreateModel();
     return View(model);
 }