public SpamAdRequestModel SpamRequestAd(SpamAdRequestModel model) { SpamAdRequestModel result = CanSpamRequestAd(model.AdId); if (!result.CanSignal) { return(result); } BaseAd ad = _adRepository.GetAdById <BaseAd>(model.AdId); this.CanSpamRequestAd(model.AdId); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { SpamAdRequest req = new SpamAdRequest(); req.Ad = ad; req.RequestDate = _helper.GetCurrentDateTime(); req.RequestorEmailAddress = model.RequestorEmail; req.SpamType = _repository.Get <SpamAdType>(model.SelectedSpamAdTypeId); req.Description = model.Description; _repository.Save(req); scope.Complete(); } result.InfoMessage = "Votre signalement a correctement été transmis. Merci de votre précieuse aide dans la chasse aux mauvaises annonces !"; result.CanSignal = false; return(result); }
public DeleteAdModel DeleteAd(DeleteAdModel model) { DeleteAdModel result = new DeleteAdModel(); result.AdId = model.AdId; BaseAd ad = _adRepository.GetAdById <BaseAd>(model.AdId); if (ad == null || ad.IsDeleted) { result.InfoMessage = "Cette annonce n'existe pas ou plus."; result.CanDeleteAd = false; return(result); } if (model.Password != ad.CreatedBy.Password) { result.NbTry = ++model.NbTry; result.SelectedDeletionReasonId = model.SelectedDeletionReasonId; result.CanDeleteAd = true; return(result); } using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { ad.IsDeleted = true; ad.DeletionDate = _helper.GetCurrentDateTime(); if (model.SelectedDeletionReasonId.HasValue) { ad.DeletedReason = _repository.Get <DeletionReason>(model.SelectedDeletionReasonId); } _repository.Save <BaseAd>(ad); SearchAdCache adCache = _repository.Get <SearchAdCache>(ad.Id); if (adCache != null) { _repository.Delete <SearchAdCache>(adCache); } result.IsDeleted = true; result.InfoMessage = "Votre annonce a correctement été supprimée. Elle n'est plus disponible à la recherche."; scope.Complete(); } return(result); }
public AdImage StoreImage(Guid id, Boolean isPrimary) { AdImage image = null; using (TransactionScope scope = new TransactionScope()) { image = new AdImage(); image.Id = id; image.IsPrimary = isPrimary; image.UploadedDate = _helper.GetCurrentDateTime(); _repository.Save <AdImage>(image); scope.Complete(); } return(image); }
private AdSearchParameters CreateSearchParameters(AdvancedAdSearchModel searchQuery) { AdSearchParameters parameters = new AdSearchParameters(); if (!String.IsNullOrEmpty(searchQuery.SearchString)) { parameters.AndSearchStrings = searchQuery.SearchString.Trim().Split(' '); } parameters.CategoryIds = GetCategoryIdsFromQuery(searchQuery.CategorySelectedId); parameters.CityId = searchQuery.CitySelectedId; parameters.MinPrice = searchQuery.MinPrice; parameters.MaxPrice = searchQuery.MaxPrice; // -- Vehicles specific properties -- // if (searchQuery.AgeBracketSelectedId.HasValue) { parameters.MaxYear = _referenceServices.GetAllAgeBrackets()[searchQuery.AgeBracketSelectedId.Value].LowValue; parameters.MaxYear = _helperService.GetCurrentDateTime().Year - parameters.MaxYear; parameters.MinYear = _referenceServices.GetAllAgeBrackets()[searchQuery.AgeBracketSelectedId.Value].HighValue; parameters.MinYear = _helperService.GetCurrentDateTime().Year - parameters.MinYear; } if (searchQuery.KmBracketSelectedId.HasValue) { parameters.MinKm = _referenceServices.GetAllKmBrackets()[searchQuery.KmBracketSelectedId.Value].LowValue; parameters.MaxKm = _referenceServices.GetAllKmBrackets()[searchQuery.KmBracketSelectedId.Value].HighValue; } if (searchQuery.EngineSizeBracketSelectedId.HasValue) { parameters.MinEngineSize = _referenceServices.GetAllEngineSizeBrackets()[searchQuery.EngineSizeBracketSelectedId.Value].LowValue; parameters.MaxEngineSize = _referenceServices.GetAllEngineSizeBrackets()[searchQuery.EngineSizeBracketSelectedId.Value].HighValue; } parameters.BrandId = searchQuery.BrandSelectedId; parameters.FueldId = searchQuery.FuelSelectedId; parameters.IsAuto = searchQuery.IsAutomatic; //-- Real Estate specific properties --// parameters.RealEstateTypeId = searchQuery.SelectedRealEstateTypeId; parameters.DistrictId = searchQuery.SelectedDistrictId; parameters.IsFurnished = searchQuery.IsFurnished; if (searchQuery.NbRoomsBracketSelectedId.HasValue) { parameters.MinNbRooms = _referenceServices.GetAllRealEstateNbRoomsBrackets()[searchQuery.NbRoomsBracketSelectedId.Value].LowValue; parameters.MaxNbRooms = _referenceServices.GetAllRealEstateNbRoomsBrackets()[searchQuery.NbRoomsBracketSelectedId.Value].HighValue; } if (searchQuery.SurfaceAreaBracketSelectedId.HasValue) { parameters.MinSurfaceArea = _referenceServices.GetAllSurfaceAreaBrackets()[searchQuery.SurfaceAreaBracketSelectedId.Value].LowValue; parameters.MaxSurfaceArea = _referenceServices.GetAllSurfaceAreaBrackets()[searchQuery.SurfaceAreaBracketSelectedId.Value].HighValue; } //-- Water sport specific properties --// parameters.MotorBoatTypeId = searchQuery.SelectedMotorBoatTypeId; parameters.MotorEngineTypeId = searchQuery.SelectedMotorTypeId; parameters.SailingBoatTypeId = searchQuery.SelectedSailingBoatTypeId; parameters.HullTypeId = searchQuery.SelectedHullTypeId; parameters.WaterTypeId = searchQuery.SelectedWaterTypeId; parameters.MinLength = searchQuery.MinLength; parameters.MaxLength = searchQuery.MaxLength; parameters.MinHp = searchQuery.MinHp; parameters.MaxHp = searchQuery.MaxHp; return(parameters); }
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); }