public ViewResult CreateBlog() { EditBlogModel model = new EditBlogModel() { Blogs = new Blog(), Author = new SelectList(db.Author, "Id", "Name"), Theme = new SelectList(db.Theme, "Id", "Name") }; return View("EditBlogPost", model); }
private void FillModelEditBlog(ref EditBlogModel model, int Id) { model = model ?? new EditBlogModel(); model.Blogs = db.Blog.FirstOrDefault(p => p.Id == Id); model.Author = new SelectList(db.Author, "Id", "Name"); model.Theme = new SelectList(db.Theme, "Id", "Name"); }
public ActionResult EditBlogPost(EditBlogModel model, HttpPostedFileBase image) { if (ModelState.IsValid) { if (image != null) { model.Blogs.ImageMimeType = image.ContentType; model.Blogs.ImageData = new byte[image.ContentLength]; image.InputStream.Read(model.Blogs.ImageData, 0, image.ContentLength); } SaveBlogPost(model.Blogs); TempData["message"] = string.Format("{0} has been saved", model.Blogs.Name); return RedirectToAction("Index"); } else { // there is something wrong with the data values FillModelEditBlog(ref model, model.Blogs.Id); return View(model); } }