Exemplo n.º 1
0
        // Add new Classified Ad
        public ClassifiedAdBase AddClassifiedAd(ClassifiedAdAdd newItem)
        {
            // 1. Set time
            // 2. Add item to db
            // 3. Add photos to data store then to temporary collection
            // 4. Create thumbnail image
            // 5. Add Location
            // 6. Add collection to db item
            // 7. Save database
            // set up automapper to map classified

            return(Mapper.Map <ClassifiedAdBase>(newItem));
        }
Exemplo n.º 2
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"));
        }