public ActionResult CreateAd(AdViewModel ad) { var cat = bridge.GetCategoryByName(ad.CategoryName); ad.UserId = HttpContext.Request.Cookies["id"].Value; Ad newAd = new Ad { AdName = ad.AdName, Info = ad.Info, PicPath = "-", CategoryId = cat.Id, CreateDate = DateTime.Now.Date, AuthorName = ad.AuthorName != "" && ad.AuthorName != null ? ad.AuthorName : "-", AuthorEmail = ad.AuthorEmail != "" && ad.AuthorEmail != null ? ad.AuthorEmail : "-", AuthorPhone = ad.AuthorPhone != "" && ad.AuthorPhone != null ? ad.AuthorPhone : "-", ProductPlacement = ad.ProductPlacement, ProductState = ad.ProductState, ProductType = ad.ProductType, UserId = HttpContext.Request.Cookies["id"].Value }; if (Request.Files.Count > 0) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("/Content/Pics/"), fileName); newAd.PicPath = path; file.SaveAs(path); } } else { newAd.PicPath = "/Content/Pics/Standart.png"; } bridge.CreateAd(newAd); return(RedirectToAction("CategoryIndex")); }