コード例 #1
0
        public async Task <IActionResult> AdCreationAdInfo(PrenumerantDto prenumerant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Bad prenumerant"));
            }

            var newAd = new AdPrenumerantDto()
            {
                prenumerantInfo = prenumerant
            };

            newAd.Ad.PrisAnnons = 0.0f; /* Should not be controller's responsibility */
            try
            {
                return(View("AdCreationAdInfo", newAd));
            }
            catch
            {
                return(BadRequest("Unknown error"));
            }
        }
コード例 #2
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"));
        }