Пример #1
0
        public ActionResult show(int adid)
        {
            Ad ad = _adRepo.GetAdById(adid);

            if (ad != null)
            {
                AdModel model = new AdModel();
                model.AdId       = ad.AdId;
                model.CategoryId = ad.CategoryId;
                model.City       = ad.City;
                if (ad.Description.Length > 215)
                {
                    ad.Description = ad.Description.Substring(0, 215) + ".....";
                }
                model.Description = ad.Description;
                model.Locality    = ad.Locality;
                model.Price       = ad.Price;
                model.Title       = ad.Title;
                model.ValidTill   = ad.ValidTill;
                model.UserId      = ad.UserId;
                model.PosdtedOn   = ad.PostedDate;
                var categories = Static.GetCategories();
                var cat        = categories.Where(t => t.CategoryId == ad.CategoryId).FirstOrDefault();
                model.CategoryName = cat.CategoryName;

                return(View(model));
            }
            else
            {
                ViewBag.Error = "Sorry , no such ad";
                return(View("Invalid"));
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        // GET: Ads/Details/5
        public IActionResult AdDetails(int id)
        {
            var ad = _adRepository.GetAdById(id);

            if (ad == null)
            {
                return(NotFound());
            }
            return(View(ad));
        }
Пример #4
0
        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);
        }
Пример #5
0
        public ContactAdModel ContactAd(ContactAdModel model)
        {
            //ContactAdModel result = new ContactAdModel(model.AdId);
            BaseAd ad = _adRepository.GetAdById <BaseAd>(model.AdId);

            if (ad == null || ad.IsDeleted)
            {
                model.InfoMessage  = "Cette annonce n'existe pas ou plus.";
                model.CanContactAd = false;
                return(model);
            }
            //Should never happened, and should be logged for investigation if it does
            if (ad.CreatedBy == null)
            {
                model.InfoMessage  = "Impossible de contacter l'annonceur.";
                model.CanContactAd = false;
                return(model);
            }
            User user = _repository.Get <User>(ad.CreatedBy.Id);

            if (user == null)
            {
                model.InfoMessage  = "Impossible de contacter l'annonceur.";
                model.CanContactAd = false;
                return(model);
            }
            model.EmailTo = user.Email;
            SendEmailToUser(model);
            if (model.CopySender)
            {
                model.EmailTo = model.Email;
                SendEmailToUser(model);
            }
            model.CanContactAd = true;
            model.InfoMessage  = "Votre message a été envoyé !";
            return(model);
        }
Пример #6
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);
        }
Пример #7
0
 public Ad GetAdById(long adId)
 {
     return(_adRepository.GetAdById <Ad>(adId));
 }