public void Edit(Post post, HttpPostedFileBase file=null) { if (file != null) { post.PreviewPhoto = new BinaryReader(file.InputStream).ReadBytes(file.ContentLength); db.Entry(post).State = System.Data.Entity.EntityState.Modified; } else { var item = Get(post.ID); item.Title = post.Title; item.Body = post.Body; item.Preview = post.Preview; } db.SaveChanges(); }
public ActionResult Create(Post post, HttpPostedFileBase file) { if (ModelState.IsValid && file != null) { _rep.Create(post, file); TempData["message"] = "Статья опубликована"; TempData["type"] = 1; return RedirectToAction("Index"); } else { ModelState.AddModelError("", "заполните все поля"); } return View(post); }
public void Delete(Post post) { db.Posts.Remove(post); db.SaveChanges(); }
public void Create(Post post,HttpPostedFileBase file) { post.PreviewPhoto = new BinaryReader(file.InputStream).ReadBytes(file.ContentLength); db.Posts.Add(post); db.SaveChanges(); }
public ActionResult Edit(Post post, HttpPostedFileBase file = null, int cpage = 1) { if (ModelState.IsValid) { _rep.Edit(post, file); TempData["message"] = "Статья отредактирована"; TempData["type"] = 1; return RedirectToAction("Index", new { page = cpage }); } return View(post); }