Example #1
0
        public PostCommentTest()
        {
            CommentTest comment = new CommentTest();
            AddDependentObject(comment);

            PostTest Post = new PostTest();
            AddDependentObject(Post);

            mPostComment = new PostComment();
            mPostComment.Comment = comment.Comment;
            mPostComment.Post = Post.Post;
        }
Example #2
0
 public static void Notify(PostComment comment)
 {
     MailMessage message = new MailMessage();
     message.From = new MailAddress(ConfigurationManager.AppSettings["Email"]);
     message.To.Add(new MailAddress(ConfigurationManager.AppSettings["Email"]));
     message.Subject = string.Format("New Comment @ {0}", ConfigurationManager.AppSettings["Url"]);
     message.IsBodyHtml = true;
     StringBuilder sb = new StringBuilder();
     sb.AppendFormat("<P><b>{2}</b> ({3}) posted a <a href='{0}ShowPost.aspx?id={1}'>new comment</a> to {0}.</P>",
         ConfigurationManager.AppSettings["Url"], comment.Post.Id, comment.Comment.OwnerLogin.Name, comment.Comment.OwnerLogin.Email);
     ReferencesRedirector redirector = new ReferencesRedirector(comment.Post.Id, "Post");
     sb.AppendFormat("<P>{0}</P>", Renderer.RenderEx(
         comment.Comment.Text, ConfigurationManager.AppSettings["url"], redirector.ReferUri));
     message.Body = sb.ToString();
     SmtpClient client = new SmtpClient();
     client.Send(message);
 }
Example #3
0
 public TransitPostComment(ISession session, DBlog.Data.PostComment o, string ticket)
     : base(session, o.Post.Id, o.Comment, TransitPost.GetAccess(session, o.Post, ticket))
 {
     AssociatedType = "Post";
 }
Example #4
0
 public TransitPostComment(ISession session, DBlog.Data.PostComment o)
     : base(session, o.Post.Id, o.Comment)
 {
     AssociatedType = "Post";
 }
Example #5
0
        public int CreateOrUpdatePostComment(string ticket, int post_id, TransitComment t_comment)
        {
            using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
            {
                ISession session = DBlog.Data.Hibernate.Session.Current;

                Post post = (Post)session.Load(typeof(Post), post_id);

                if (string.IsNullOrEmpty(ticket))
                {
                    // anonymous
                    t_comment.LoginId = 0;
                }
                else if (t_comment.LoginId == 0)
                {
                    // logged in
                    t_comment.LoginId = ManagedLogin.GetLoginId(ticket);
                }
                else if (t_comment.LoginId != ManagedLogin.GetLoginId(ticket) && ! ManagedLogin.IsAdministrator(session, ticket))
                {
                    // not admin and trying to post a comment as someone else
                    throw new ManagedLogin.AccessDeniedException();
                }

                Comment comment = t_comment.GetComment(session);
                comment.Modified = DateTime.UtcNow;
                if (comment.Id == 0) comment.Created = comment.Modified;
                session.SaveOrUpdate(comment);

                if (t_comment.ParentCommentId != 0 && t_comment.Id == 0)
                {
                    Thread thread = new Thread();
                    thread.Comment = comment;
                    thread.ParentComment = (Comment) session.Load(typeof(Comment), t_comment.ParentCommentId);
                    session.Save(thread);
                }

                PostComment post_comment = session.CreateCriteria(typeof(PostComment))
                    .Add(Expression.Eq("Post.Id", post_id))
                    .Add(Expression.Eq("Comment.Id", t_comment.Id))
                    .UniqueResult<PostComment>();

                if (post_comment == null)
                {
                    post_comment = new PostComment();
                    post_comment.Post = post;
                    post_comment.Comment = comment;
                    session.SaveOrUpdate(post_comment);
                }

                ManagedPostComment.Notify(post_comment);

                session.Flush();
                return comment.Id;
            }
        }