예제 #1
0
 public int CreateOrUpdateComment(string ticket, TransitComment t_comment)
 {
     using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
     {
         ISession session = DBlog.Data.Hibernate.Session.Current;
         CheckAdministrator(session, ticket);
         Comment comment = t_comment.GetComment(session);
         session.SaveOrUpdate(comment);
         session.Flush();
         return comment.Id;
     }
 }
예제 #2
0
 public void save_Click(object sender, EventArgs e)
 {
     try
     {
         TransitComment t_comment = new TransitComment();
         t_comment.Id = RequestId;
         t_comment.Text = CheckInput("Comment", inputText.Content);
         t_comment.IpAddress = Request.ServerVariables["REMOTE_ADDR"];
         t_comment.ParentCommentId = GetId("pid");
         PostComment.Id = SessionManager.BlogService.CreateOrUpdatePostComment(
             SessionManager.Ticket, GetId("sid"), t_comment);
         SessionManager.Invalidate<TransitPost>();
         SessionManager.Invalidate<TransitPostComment>();
         Response.Redirect(string.Format("./ShowPost.aspx?id={0}", GetId("sid")));
     }
     catch (Exception ex)
     {
         ReportException(ex);
     }
 }
예제 #3
0
 public void save_Click(object sender, EventArgs e)
 {
     try
     {
         TransitComment t_comment = new TransitComment();
         t_comment.Id = RequestId;
         t_comment.Text = CheckInput("Comment", inputText.Text);
         t_comment.IpAddress = Request.ServerVariables["REMOTE_ADDR"];
         t_comment.ParentCommentId = GetId("pid");
         ImageComment.Id = SessionManager.BlogService.CreateOrUpdateImageComment(
             SessionManager.Ticket, GetId("sid"), t_comment);
         SessionManager.Invalidate<TransitImage>();
         SessionManager.Invalidate<TransitImageComment>();
         Response.Redirect(ReturnUrl);
     }
     catch (Exception ex)
     {
         ReportException(ex);
     }
 }
예제 #4
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;
            }
        }