Ejemplo n.º 1
0
        public ActionResult Create(AdPrenumerantDto adPrenumerantDto)
        {
            if (!ModelState.IsValid || !(Math.Abs(adPrenumerantDto.Ad.PrisAnnons - 0.0) < 0.0000001))
            {
                return(ValidationProblem());
            }

            try
            {
                Ad ad = Mapper.Map <Ad>(adPrenumerantDto.Ad);
                PrenumerantAnnonsor prenumerant = Mapper.Map <PrenumerantAnnonsor>(adPrenumerantDto.prenumerantInfo);
                _annonsRepository.CreateAd(ad, prenumerant);
                if (!_annonsRepository.Save())
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }

            return(RedirectToAction("Index", "Ads"));
        }
Ejemplo n.º 2
0
        public ActionResult Create(AdForetagDto adForetagDto)
        {
            if (!ModelState.IsValid || !(Math.Abs(adForetagDto.Ad.PrisAnnons - 40.0) < 0.0000001))
            {
                return(ValidationProblem());
            }

            try
            {
                Ad ad = _mapper.Map <Ad>(adForetagDto.Ad);
                ForetagAnnonsor foretag = _mapper.Map <ForetagAnnonsor>(adForetagDto.foretagDto);
                _annonsRepository.CreateAd(ad, foretag);
                if (!_annonsRepository.Save())
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }

            return(RedirectToAction("Index", "Ads"));
        }