/// <summary>
        /// Add a new comment for a property.  Expects:
        /// id: string, property id
        /// level: CommentAccessLevel string
        /// text: comment text (optional, must have text or image)
        /// form file: image (optional)
        /// </summary>
        protected override void InternalPUT(HttpContext context, HandlerTimedCache cache)
        {
            var user = UserHelper.GetUser(context.User.Identity.Name);

            if (user == null || !user.CanAddComments())
            {
                context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                context.Response.Write("Must be logged in to leave a comment");
                return;
            }

            var id    = WebUtil.GetParam(context, "id", false);
            var level = WebUtil.ParseEnumParam <CommentAccessLevel>(context, "level");
            var text  = WebUtil.GetParam(context, "text", true);

            byte[] image = InputStreamToByteArray(context);

            if (text == null && image == null)
            {
                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                context.Response.Write("Must include either text or image comment (or both).");
                return;
            }

            context.Response.Write(JToken.FromObject(
                                       Comment.AddComment(id, user, level, text, image)
                                       ));
        }
        public void TestAccessLevelChagned()
        {
            var c = Comment.AddComment("NL0001", org1, CommentAccessLevel.Public, null, null);

            c.Update(org1, null, null, false, CommentAccessLevel.SameOrg);

            Assert.AreEqual(c.AccessLevel, CommentAccessLevel.SameOrg);
        }
Пример #3
0
 // for guest user reply a comment
 public int NewComment(int postid, string commentcontent, DateTime publisheddate, string poststatus, int parentcomment)
 {
     Comment c = new Comment();
     int i = c.AddComment(postid, commentcontent, publisheddate, poststatus,parentcomment);
     if (i == 1)
         return 1;
     else
         return 0;
 }
        public void TestImageRemoved()
        {
            var img = new byte[14];

            var c = Comment.AddComment("NL0001", org1, CommentAccessLevel.SameOrg, null, img);

            c.Update(org1, null, null, true);

            var updatedComment = _commentDao.GetFirst("Id", c.Id);

            Assert.IsFalse(updatedComment.HasPicture, "Image was not removed");
        }
        public void TestEditReplacesImage()
        {
            var orig   = new byte[10];
            var update = new byte[42];

            var comment = Comment.AddComment("NL00x", org1, CommentAccessLevel.Public, "JOHN RAMBO", null);

            comment.Update(org1, null, update, false);
            var updatedComment = _commentDao.GetFirst("Id", comment.Id);

            Assert.AreEqual(42, updatedComment.Image.Length, "New image failed to save");
        }
        public void TestHasPicture()
        {
            var image = new Bitmap(200, 200);
            var g     = Graphics.FromImage(image);

            g.DrawLine(new Pen(Color.Black), 1, 1, 2, 2);
            g.Save();
            var ms = new MemoryStream();

            image.Save(ms, ImageFormat.Png);
            var c = Comment.AddComment("test", org1, CommentAccessLevel.Public, "My Comment", ms.ToArray());

            Assert.IsTrue(c.HasPicture);
        }
Пример #7
0
    public int NewComment(int postid, string commentcontent, DateTime publisheddate, string poststatus, int parentcomment)  // for guest user reply a comment
    {
        Comment c = new Comment();
        int     i = c.AddComment(postid, commentcontent, publisheddate, poststatus, parentcomment);

        if (i == 1)
        {
            return(1);
        }
        else
        {
            return(0);
        }
    }
Пример #8
0
    public int NewComment(int userid, int postid, string commentcontent, DateTime publisheddate, string poststatus)  // for login user new a comment
    {
        Comment c = new Comment();
        int     i = c.AddComment(userid, postid, commentcontent, publisheddate, poststatus);

        if (i == 1)
        {
            return(1);
        }
        else
        {
            return(0);
        }
    }
        public void TestUpdateTextNotImage()
        {
            string orig = "First text",
                   upd  = "Second text";
            var img     = new byte[14];

            var c = Comment.AddComment("NL0001", org1, CommentAccessLevel.SameOrg, orig, img);

            c.Update(org1, upd, null, false);

            var updatedComment = _commentDao.GetFirst("Id", c.Id);

            Assert.AreEqual(upd, updatedComment.Text, "Text failed to save");
            Assert.AreEqual(14, updatedComment.Image.Length, "Image was improperly updated");
        }
        private void TestUserAuthorized(User user, bool canEdit)
        {
            TestDelegate edit = delegate
            {
                var comment = Comment.AddComment("2x3", org1, CommentAccessLevel.Public, "JOHN RAMBO", null);
                comment.Update(user, "This may or may not be allowed", null, false);
            };

            if (canEdit)
            {
                Assert.DoesNotThrow(edit);
            }
            else
            {
                Assert.Throws <UnauthorizedToEditCommentException>(edit);
            }
        }
        public void Setup()
        {
            _userDao.Truncate();
            _commentDao.Truncate();

            sys = new User
            {
                Email          = "",
                EmailConfirmed = true,
                Name           = "SysAdmin",
                UserName       = "******",
                Roles          = "SysAdmin,public"
            };
            org1 = new User()
            {
                Email          = "",
                EmailConfirmed = true,
                Name           = "Orggy Org",
                UserName       = "******",
                Roles          = "network,public",
                Organization   = 1
            };
            org2 = new User()
            {
                Email          = "",
                EmailConfirmed = true,
                Name           = "John Rambo",
                UserName       = "******",
                Roles          = "network,public",
                Organization   = 2
            };
            UserHelper.Save(sys);
            UserHelper.Save(org1);
            UserHelper.Save(org2);

            Comment.AddComment("1a", sys, CommentAccessLevel.Network, "Network folks only", null);
            Comment.AddComment("1a", sys, CommentAccessLevel.Public, "Hello, everyone", null);
            Comment.AddComment("1a", org1, CommentAccessLevel.SameOrg, "Hello, co-workers", null);
        }
Пример #12
0
 bool InterfaceComment.AddComment(Comment comment)
 {
     return(comment.AddComment());
 }
Пример #13
0
 public bool AddComment(Comment comment)
 {
     return(comment.AddComment());
 }
        public void TestHasNoPicture()
        {
            var c = Comment.AddComment("test", org1, CommentAccessLevel.Public, "My Comment", null);

            Assert.IsFalse(c.HasPicture);
        }
        public void AddCommentSansImage()
        {
            var c = Comment.AddComment("test", org1, CommentAccessLevel.Public, "My Comment", null);

            Assert.AreNotEqual(0, c.Id);
        }