Beispiel #1
0
        public ActionResult CreateAd(ClassifiedAdAdd newItem)
        {
            if (!ModelState.IsValid)
            {
                var retItem = Mapper.Map <ClassifiedAdAddForm>(newItem);
                var f       = ClassifiedAdManager.GetSubCatWithCat(newItem.SubCatId);

                // Create form
                retItem.SubCategoryId   = f.Id;
                retItem.SubCategoryName = f.Name;
                retItem.CategoryName    = f.CategoryName;
                retItem.ConfigureForm(ClassifiedAdManager);
                retItem.AdInfo = null;

                var getinfo = f.AdInfoTemplate?.RecommendedInfo;
                if (getinfo != null)
                {
                    if (getinfo.Count() > 0)
                    {
                        retItem.AdInfo = new List <InfoForm>();
                        retItem.AdInfo = getinfo.ToList();
                    }
                }

                return(View(retItem));
            }
            // Prevent double post
            if (TempData["hasBeenPosted"] == null)
            {
                TempData["hasBeenPosted"] = true;
                // Sanitize description
                newItem.Description = new HtmlSanitizer().Sanitize(newItem.Description);

                // Process the input
                var addedItem = ClassifiedAdManager.AddClassifiedAd(newItem);

                if (addedItem == null)
                {
                    return(View(newItem));
                }
                else
                {
                    // Prevent user going back after posting ad
                    TempData["isPostedCreate"] = true;
                    return(RedirectToAction("MyAdPreview", new { adId = addedItem.Id }));
                }
            }

            return(RedirectToAction("MyAdList"));
        }