public ActionResult Create([Bind(Include = "Id,Created,Updated,Title,Slug,Body,MediaURL,Published")] BlogPost blogPost, HttpPostedFileBase image) { if (ModelState.IsValid) { var Slug = StringUtilities.URLFriendly(blogPost.Title); //var Snip = SnippetStripper.StripTagsCharArray(blogPost.Body); if (String.IsNullOrWhiteSpace(Slug)) { ModelState.AddModelError("Title", "Invalid title"); return(View(blogPost)); } if (db.BlogPosts.Any(p => p.Slug == Slug)) { ModelState.AddModelError("Title", "Title must be unique"); return(View(blogPost)); } if (ImageUploadValidator.IsWEebFriendlyImage(image)) { var fileName = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); blogPost.MediaURL = "/Uploads/" + fileName; } return(RedirectToAction("Index")); } return(View(blogPost)); }
public ActionResult Edit([Bind(Include = "Id,Created,Updated,Title,Slug,Body,MediaURL,Published")] BlogPost blogPost, HttpPostedFileBase image) { if (ModelState.IsValid) { if (ImageUploadValidator.IsWEebFriendlyImage(image)) { var fileName = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); blogPost.MediaURL = "/Uploads/" + fileName; } db.Entry(blogPost).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(blogPost)); }