Example #1
0
 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();
 }
Example #2
0
        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);
        }
Example #3
0
 public void Delete(Post post)
 {
     db.Posts.Remove(post);
     db.SaveChanges();
 }
Example #4
0
 public void Create(Post post,HttpPostedFileBase file)
 {
     post.PreviewPhoto = new BinaryReader(file.InputStream).ReadBytes(file.ContentLength);
     db.Posts.Add(post);
     db.SaveChanges();
 }
Example #5
0
 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);
 }