public ActionResult AddComment(CommentsVM comment, int postId) { //bool result = false; Comment commentEntity = null; string currentUserId = User.Identity.GetUserId(); int userId = 1; //int.Parse(currentUserId); //(int)Session["UserID"]; List <User> GetUsers = sp.GetUsers(); var user = GetUsers.FirstOrDefault(u => u.Id == currentUserId); var post = sp.GetPosts().FirstOrDefault(p => p.PostID == postId); if (comment != null) { commentEntity = new Comment { CommentMsg = comment.CommentMsg, CommentedDate = DateTime.Now }; if (user != null && post != null) { post.Comments.Add(commentEntity); user.Comments.Add(commentEntity); //sq.SaveChanges( ); //dbContext.SaveChanges(); //result = true; sp.Commit(); su.Commit(); } } return(RedirectToAction("GetComments", "Comments", new { postId = postId })); }
// GET: Post //public ActionResult Index() //{ // List<Post> Posts = new List<Post>(); // Posts = sp.GetPosts(); // return View(); //} public ActionResult Index(int?idcat, string recherch) { List <Post> Posts = new List <Post>(); try { //ViewBag.categoriepost = ps.GetCategoriePost(); if (recherch != null) { Posts = sp.GetPostsByrecherch(recherch); } else { Posts = sp.GetPosts(); // Posts = idcat == null ? ps.GetPosts() : ps.GetPostsBycat(idcat); } return(View(Posts)); } catch (Exception ex) { return(View(Posts)); } }