Esempio n. 1
0
        [HttpPost] //ValidateAntiForgeryToken
        public ActionResult Create(AdvertisementViewModel model)
        {
            if (TempData["NeedPayment"] != null)
            {
                TempData["NeedPayment"] = null;
            }

            if (!ModelState.IsValid)
            {
                PopulateDropDownListAndKeys(model);
                return(View(model));
            }
            if (!model.IsAdmin && !model.IsPaid)
            {
                TempData["NeedPayment"] = true;
                PopulateDropDownListAndKeys(model);
                return(View(model));
            }

            var ad = Mapper.Map <Advertisement>(model);

            ad.UserId         = CurrentUserId.ToString();
            ad.CreatedByAdmin = model.IsAdmin;
            _adsService.Create(ad);

            return(RedirectToAction(nameof(Index)));
        }