Пример #1
0
        public void AdDetailsModel_ctor()
        {
            // Given
            City c = new City()
            {
                Label = "Nouméa"
            };

            User u = new User()
            {
                Firstname = "Nicolas"
            };

            Category cat = new Category()
            {
                Label = "Auto",
                LabelUrlPart = "Auto",
                ParentCategory = new Category { Label = "Véhicules", LabelUrlPart = "Vehicules" }
            };

            Ad ad = new Ad()
            {
                Id = 17,
                Title = "title",
                Price = 1270,
                City = c,
                CreatedBy = u,
                CreationDate = new DateTime(2012, 05, 12, 17, 26, 08),
                Body = "body",
            };
            cat.AddAd(ad);
            ad.Images.Add(new AdImage() { Id = Guid.Parse("e9da8b1e-aa77-401b-84e0-a1290130b7b7") });
            ad.Images.Add(new AdImage() { Id = Guid.Parse("e9da8b1e-aa77-401b-84e0-a1290130b7b9") });

            // When
            AdDetailsModel model = new AdDetailsModel(ad);

            // Then
            Assert.AreEqual("title", model.Title);
            Assert.AreEqual("Nouméa", model.Location);
            Assert.AreEqual("Nicolas", model.UserFirstName);
            Assert.AreEqual("samedi 12 mai 2012 17:26", model.CreationDateString);
            Assert.AreEqual("body", model.Body);
            Assert.AreEqual("1 270 Francs", model.Price);
            Assert.AreEqual(17, model.AdId);
            Assert.AreEqual(2, model.ImagesIds.Count);
            Assert.AreEqual("e9da8b1e-aa77-401b-84e0-a1290130b7b7", model.ImagesIds[0]);
            Assert.AreEqual("e9da8b1e-aa77-401b-84e0-a1290130b7b9", model.ImagesIds[1]);
            Assert.AreEqual("Auto", model.Category);
            Assert.AreEqual("Auto", model.CategoryUrlPart);
            Assert.AreEqual("Véhicules", model.CategoryGroup);
            Assert.AreEqual("Vehicules", model.CategoryGroupUrlPart);
        }
Пример #2
0
        public HttpResponseMessage Get(long id)
        {
            HttpResponseMessage response;
            Ad ad = _adServices.GetAdById(id);
            if (ad == null)
            {
                response = new HttpResponseMessage(HttpStatusCode.NotFound);
            }
            else
            {
                AdDetailsModel adModel = new AdDetailsModel(ad);
                response = Request.CreateResponse(HttpStatusCode.OK, adModel);
            }

            return response;
        }
Пример #3
0
        protected AdDetailsModel CreateAdDetailsModelFromAd(AdTypeEnum adType, long adId)
        {
            AdDetailsModel model = null;
            BaseAd ad = null;

            // Get the right Ad based on its type
            switch (adType)
            {
                case AdTypeEnum.Ad:
                    ad = _adRepository.GetAdById<Ad>(adId);
                    model = new AdDetailsModel(ad);
                    break;

                case AdTypeEnum.CarAd:
                    ad = _adRepository.GetAdById<CarAd>(adId);
                    model = new CarAdDetailsModel(ad as CarAd);
                    break;

                case AdTypeEnum.MotoAd:
                    ad = _adRepository.GetAdById<MotoAd>(adId);
                    model = new MotoAdDetailsModel(ad as MotoAd);
                    break;

                case AdTypeEnum.OtherVehiculeAd:
                    ad = _adRepository.GetAdById<OtherVehicleAd>(adId);
                    model = new OtherVehicleAdDetailsModel(ad as OtherVehicleAd);
                    break;

                case AdTypeEnum.SailingBoatAd:
                    ad = _adRepository.GetAdById<SailingBoatAd>(adId);
                    model = new SailingBoatAdDetailsModel(ad as SailingBoatAd, _helperService);
                    break;

                case AdTypeEnum.MotorBoatAd:
                    ad = _adRepository.GetAdById<MotorBoatAd>(adId);
                    model = new MotorBoatAdDetailsModel(ad as MotorBoatAd, _helperService);
                    break;

                case AdTypeEnum.MotorBoatEngineAd:
                    ad = _adRepository.GetAdById<MotorBoatEngineAd>(adId);
                    model = new MotorBoatEngineAdDetailsModel(ad as MotorBoatEngineAd);
                    break;

                case AdTypeEnum.WaterSportAd:
                    ad = _adRepository.GetAdById<WaterSportAd>(adId);
                    model = new WaterSportAdDetailsModel(ad as WaterSportAd);
                    break;

                case AdTypeEnum.RealEstateAd:
                    ad = _adRepository.GetAdById<RealEstateAd>(adId);
                    model = new RealEstateAdDetailsModel(ad as RealEstateAd);
                    break;

                default:
                    return null;
            }

            // Compute whether or not this Ad is new (less than 3 days)
            model.IsNew = ad.CreationDate > _helperService.GetCurrentDateTime().AddHours(-72);

            return model;
        }
Пример #4
0
 // POST api/AdAPI
 public void Post(AdDetailsModel adModel)
 {
 }