示例#1
0
        public ImageCommentTest()
        {
            ImageTest image = new ImageTest();
            AddDependentObject(image);

            CommentTest comment = new CommentTest();
            AddDependentObject(comment);

            mImageComment = new ImageComment();
            mImageComment.Image = image.Image;
            mImageComment.Comment = comment.Comment;
        }
示例#2
0
 public TransitImageComment(ISession session, DBlog.Data.ImageComment o, bool hasaccess)
     : base(session, o.Image.Id, o.Comment, hasaccess)
 {
     AssociatedType = "Image";
 }
示例#3
0
 public TransitImageComment(ISession session, DBlog.Data.ImageComment o, string ticket)
     : this(session, o, TransitImage.HasAccess(session, o.Image, ticket))
 {
     AssociatedType = "Image";
 }
示例#4
0
        public int CreateOrUpdateImageComment(string ticket, int image_id, TransitComment t_comment)
        {
            using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
            {
                ISession session = DBlog.Data.Hibernate.Session.Current;

                Image image = (Image)session.Load(typeof(Image), image_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 image 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);
                }

                ImageComment image_comment = session.CreateCriteria(typeof(ImageComment))
                    .Add(Expression.Eq("Image.Id", image_id))
                    .Add(Expression.Eq("Comment.Id", t_comment.Id))
                    .UniqueResult<ImageComment>();

                if (image_comment == null)
                {
                    image_comment = new ImageComment();
                    image_comment.Image = image;
                    image_comment.Comment = comment;
                    session.SaveOrUpdate(image_comment);
                }

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