/// <summary> /// Add item /// </summary> /// <param name="item">Comment</param> /// <returns>Comment object</returns> public CommentItem Add(CommentDetail item) { if (!Security.IsAuthorizedTo(Rights.CreateComments)) throw new UnauthorizedAccessException(); var c = new Comment(); try { var post = Post.Posts.Where(p => p.Id == item.PostId).FirstOrDefault(); c.Id = Guid.NewGuid(); c.ParentId = item.ParentId; c.IsApproved = true; c.Content = HttpUtility.HtmlAttributeEncode(item.Content); c.Author = Security.CurrentUser.Identity.Name; var profile = AuthorProfile.GetProfile(c.Author); if (profile != null && !string.IsNullOrEmpty(profile.DisplayName)) { c.Author = profile.DisplayName; } c.Email = Membership.Provider.GetUser(Security.CurrentUser.Identity.Name, true).Email; c.IP = Utils.GetClientIP(); c.DateCreated = DateTime.Now; c.Parent = post; post.AddComment(c); post.Save(); var newComm = post.Comments.Where(cm => cm.Content == c.Content).FirstOrDefault(); return Json.GetComment(newComm, post.Comments); } catch (Exception ex) { Utils.Log("Core.Data.CommentsRepository.Add", ex); return null; } }
public CommentItem Add(CommentDetail item) { return new CommentItem() { Id = Guid.NewGuid() }; }
/// <summary> /// Get comment detail /// </summary> /// <param name="c">Comment</param> /// <returns>Json comment detail</returns> public static CommentDetail GetCommentDetail(Comment c) { var jc = new CommentDetail(); jc.Id = c.Id; jc.ParentId = c.ParentId; jc.PostId = c.Parent.Id; jc.Title = c.Teaser.Length < 80 ? c.Teaser : c.Teaser.Substring(0, 80) + "..."; jc.Content = c.Content; jc.Website = c.Website == null ? "" : c.Website.ToString(); jc.Ip = c.IP; return jc; }