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); }
public ActionResult AddPost(Post post) { if (ModelState.IsValid) { repository.AddPost(post, User.Identity.Name, DateTime.Now); repository.SaveChanges(); return RedirectToAction("Index"); } return View(post); }
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); }
public void EditPost(Post post) { context.Entry(post).State = System.Data.EntityState.Modified; }
public void DeletePost(Post post) { context.Posts.Remove(post); }