示例#1
0
 public void AddPost(Post post, string user, DateTime date)
 {
     post.PostUser = user;
     post.PostDate = date;
     post.ShortPost = post.Text.Substring(0, 512);
     context.Posts.Add(post);
 }
示例#2
0
 public ActionResult AddPost(Post post)
 {
     if (ModelState.IsValid)
     {
         repository.AddPost(post, User.Identity.Name, DateTime.Now);
         repository.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(post);
 }
示例#3
0
 public ActionResult EditPost(Post post)
 {
     //TODO check for user role and allow to edit post only the same user or admin.
     if (ModelState.IsValid)
     {
         if (User.Identity.Name == post.PostUser)
         {
             repository.EditPost(post);
             repository.SaveChanges();
             return RedirectToAction("Index");
         }
     }
     return View(post);
 }
示例#4
0
 public void EditPost(Post post)
 {
     context.Entry(post).State = System.Data.EntityState.Modified;
 }
示例#5
0
 public void DeletePost(Post post)
 {
     context.Posts.Remove(post);
 }