Example #1
0
        public ActionResult New(Ad ad, HttpPostedFileBase[] images)
        {
            var manager = new SimpleAdManager(SimpleAds.Properties.Settings.Default.ConnectionString);

            ad.Images = images.Where(i => i != null).Select(i =>
            {
                Guid g          = Guid.NewGuid();
                string fileName = g + ".jpg";
                i.SaveAs(Server.MapPath("~/Uploads/" + fileName));
                return(fileName);
            });
            manager.AddAd(ad);

            //3,6,10

            List <string> adIds;

            if (Request.Cookies["adIds"] != null)
            {
                adIds = Request.Cookies["adIds"].Value.Split(',').ToList();
            }
            else
            {
                adIds = new List <string>();
            }

            adIds.Add(ad.Id.ToString());
            var cookie = new HttpCookie("adIds", String.Join(",", adIds));

            Response.Cookies.Add(cookie);

            return(RedirectToAction("Index"));
        }