public void AddCommentToComment(CommentModel comment, int? parentCommentId) { try { if (dbContext.Contents.FirstOrDefault(x => x.Id == (int)comment.ContentWherePosted.Id).Comments.FirstOrDefault(x => x.Id == (int)parentCommentId).ChildComments != null) { dbContext.Contents.FirstOrDefault(x => x.Id == (int)comment.ContentWherePosted.Id).Comments.FirstOrDefault(x => x.Id == (int)parentCommentId).ChildComments.Add(comment); } else { dbContext.Contents.FirstOrDefault(x => x.Id == (int)comment.ContentWherePosted.Id).Comments.FirstOrDefault(x => x.Id == (int)parentCommentId).ChildComments = new List<CommentModel>(); dbContext.Contents.FirstOrDefault(x => x.Id == (int)comment.ContentWherePosted.Id).Comments.FirstOrDefault(x => x.Id == (int)parentCommentId).ChildComments.Add(comment); } dbContext.SaveChanges(); } catch (Exception) { throw new Exception("Error: intente nuevamente"); } }
public ActionResult PostToContent(string ContentId, string texto, string user, string email) { int iparentContent = Convert.ToInt32(ContentId); try { UserModel us = userRepository.GetByMail(email); if (us == null) { us = new UserModel(); us.FirstDateOn = DateTime.Now; us.LastDateOn = DateTime.Now; us.UserMail = email; us.UserName = user; // userRepository.Save(us); Session["registered"] = true; } CommentModel comment = new CommentModel(); comment.Comment = texto; comment.ContentWherePosted = repository.Get(iparentContent); if (comment.ContentWherePosted == null) { throw new Exception("Error: por favor intente nuevamente"); } comment.PostingUser = us; comment.IsFatherNode = true; comment.IsActive = true; comment.DatePosted = DateTime.Now; repository.SaveComment(comment); return PartialView("SingleComment", comment); } catch (Exception e) { return new EmptyResult() ; } }