/// <summary>
        /// Delete a comment
        /// </summary>
        protected override void InternalDELETE(HttpContext context, HandlerTimedCache cache)
        {
            var    user      = UserHelper.GetUser(context.User.Identity.Name);
            var    commentId = WebUtil.ParseIntParam(context, "commentId");
            Action doDelete  = () => Comment.ById(commentId).Delete(user);

            ModifyComment(context, doDelete);
        }
        /// <summary>
        /// Partial edits to a comment, if authorized
        /// </summary>
        /// <param name="context"></param>
        /// <param name="cache"></param>
        protected override void InternalPOST(HttpContext context, HandlerTimedCache cache)
        {
            var user        = UserHelper.GetUser(context.User.Identity.Name);
            var commentId   = WebUtil.ParseIntParam(context, "commentId");
            var accessLevel = WebUtil.ParseEnumParam <CommentAccessLevel>(context, "level");
            var text        = WebUtil.GetParam(context, "text", true);
            var removeImage = WebUtil.ParseBoolParam(context, "removeImage");
            var image       = InputStreamToByteArray(context);

            Action doEdit = () => Comment.ById(commentId).Update(user, text, image, removeImage, accessLevel);

            ModifyComment(context, doEdit);
        }
Пример #3
0
        /// <summary>
        /// For a given comment id, return the image
        /// If there is no image associated, a 404
        /// Expects:
        /// id: string, comment id
        /// thumb: bool, optional render as thumbnail
        /// </summary>
        protected override void InternalGET(HttpContext context, HandlerTimedCache cache)
        {
            var user  = UserHelper.GetUser(context.User.Identity.Name);
            var thumb = false;

            WebUtil.ParseOptionalBoolParam(context, "thumb", ref thumb);

            // Default to 100x100 if in thumbnail mode, but can override.
            var width = THUMB_WIDTH;

            WebUtil.ParseOptionalIntParam(context, "w", ref width);
            var height = THUMB_HEIGHT;

            WebUtil.ParseOptionalIntParam(context, "h", ref height);

            var id = WebUtil.ParseIntParam(context, "id");

            try
            {
                var comment = Comment.ById(id);
                if (!comment.HasPicture)
                {
                    throw new CommentNotFoundException();
                }

                if (comment.IsAuthorizedToView(user))
                {
                    var img    = comment.Image;
                    var format = GetImageFormat(img);
                    context.Response.ContentType = String.Format("image/{0}", format);

                    if (thumb)
                    {
                        var ms = new MemoryStream();
                        ms.Write(img, 0, img.Length);
                        var b         = new Bitmap(ms);
                        var thumbnail = b.GetThumbnailImage(width, height, () => false, IntPtr.Zero);
                        var outStream = new MemoryStream();
                        thumbnail.Save(outStream, format);
                        img = outStream.ToArray();
                    }
                    context.Response.BinaryWrite(img);
                    return;
                }
                context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
            }
            catch (CommentNotFoundException)
            {
                context.Response.StatusCode = (int)HttpStatusCode.NotFound;
            }
        }