public ActionResult AddPost(string body, string topic) { Post post = new Post(){ Body = body, Topic = topic, Votes = 0, }; if (Request.IsAuthenticated) { post.Name = User.Identity.Name; post.UserId = 0; } else { post.Name = Session["Name"].ToString(); int id = Convert.ToInt32(Session["UserId"]); post.UserId = id; } post.DateCreated = DateTime.Now; blogRepository.Add(post); blogRepository.Save(); return Json(true); }
public ActionResult Create(Post post) { if(ModelState.IsValid) { post.Name = Session["Name"].ToString(); post.DateCreated = DateTime.Now; int id = Convert.ToInt32(Session["UserId"]); post.UserId = id; blogRepository.Add(post); blogRepository.Save(); return RedirectToAction("Page"); } return View(post); }
public ActionResult AddPostTopic(string body, string topic) { Post post = new Post() { Body = body, Topic = topic, Votes = 0 }; post.DateCreated = DateTime.Now; post.Name = User.Identity.Name; post.UserId = 0; blogRepository.Add(post); blogRepository.Save(); return Json(true); }
public void Delete(Post post) { db.Posts.Remove(post); }
//Insert/Delete Methods public void Add(Post post) { db.Posts.Add(post); }