示例#1
0
        public async Task <IActionResult> AdCreationAdInfo(ForetagDto foretagDto)
        {
            TempData["BadForetag"] = false;

            if (!ModelState.IsValid)
            {
                TempData["BadForetag"] = true;
                return(BadRequest("Unknown error"));
            }

            var newAd = new AdForetagDto()
            {
                foretagDto = foretagDto
            };

            newAd.Ad.PrisAnnons = 40.0f; /* Should not be controller's responsibility */
            try
            {
                TempData["BadForetag"] = false;
                return(View("AdCreationAdInfo", newAd));
            }
            catch
            {
                return(BadRequest("Unknown error"));
            }
        }
示例#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"));
        }