Esempio n. 1
0
        protected override void UpdateCache(CommandResponse <Comment> result)
        {
            if (result != null && result.Success)
            {
                var key = CachingKey.CommentTree(result.Response.SubmissionID.Value);

                //Prevent key-ed entries if parent isn't in cache with expiration date
                if (CacheHandler.Instance.Exists(key))
                {
                    var treeItem = result.Response.MapToTree();

                    CacheHandler.Instance.DictionaryReplace <int, usp_CommentTree_Result>(key, result.Response.ID, x =>
                    {
                        x.IsDeleted        = result.Response.IsDeleted;
                        x.Content          = result.Response.Content;
                        x.FormattedContent = result.Response.FormattedContent;
                        return(x);
                    });
                }
            }
        }
Esempio n. 2
0
        protected override void UpdateCache(Comment result)
        {
            if (result != null)
            {
                var key = CachingKey.CommentTree(result.SubmissionID.Value);

                //Prevent key-ed entries if parent isn't in cache with expiration date
                if (CacheHandler.Instance.Exists(key))
                {
                    var treeItem = result.MapToTree();

                    //CacheHandler.Instance.Replace(key, result.ID, treeItem);
                    CacheHandler.Instance.DictionaryReplace <int, usp_CommentTree_Result>(key, result.ID, x =>
                    {
                        x.Content          = result.Content;
                        x.FormattedContent = result.FormattedContent;
                        x.LastEditDate     = result.LastEditDate;
                        return(x);
                    });
                }
            }
        }
Esempio n. 3
0
        protected override void UpdateCache(CommandResponse <Domain.Models.Comment> result)
        {
            if (result.Success)
            {
                var c   = result.Response;
                var key = CachingKey.CommentTree(result.Response.SubmissionID.Value);

                //Prevent key-ed entries if parent isn't in cache with expiration date
                if (CacheHandler.Instance.Exists(key))
                {
                    //Add new comment
                    var treeItem = c.MapToTree();
                    treeItem.UserName = UserName;
                    CacheHandler.Instance.DictionaryReplace(key, c.ID, treeItem);

                    if (c.ParentID.HasValue)
                    {
                        //Update parent's ChildCount in cache
                        CacheHandler.Instance.DictionaryReplace <int, usp_CommentTree_Result>(key, c.ParentID.Value, x => { x.ChildCount += 1; return(x); });
                    }
                }
            }
        }
Esempio n. 4
0
 protected override void UpdateCache(CommandResponse <Models.Comment> result)
 {
     if (result.Success)
     {
         var comment = result.Response;
         //purge subscriptions from cache because they just changed
         CacheHandler.Instance.DictionaryReplace <int, usp_CommentTree_Result>(CachingKey.CommentTree(comment.SubmissionID.Value), comment.ID, x => { x.IsDistinguished = comment.IsDistinguished; return(x); }, true);
     }
 }
Esempio n. 5
0
        public JsonResult DistinguishComment(int commentId)
        {
            var commentToDistinguish = _db.Comments.Find(commentId);

            if (commentToDistinguish != null)
            {
                // check to see if request came from comment author
                if (User.Identity.Name == commentToDistinguish.UserName)
                {
                    // check to see if comment author is also sub mod or sub admin for comment sub
                    if (ModeratorPermission.HasPermission(User.Identity.Name, commentToDistinguish.Submission.Subverse, ModeratorAction.DistinguishContent))
                    {
                        // mark the comment as distinguished and save to db
                        if (commentToDistinguish.IsDistinguished)
                        {
                            commentToDistinguish.IsDistinguished = false;
                        }
                        else
                        {
                            commentToDistinguish.IsDistinguished = true;
                        }

                        _db.SaveChangesAsync();

                        //Update Cache
                        CacheHandler.Instance.DictionaryReplace <int, usp_CommentTree_Result>(CachingKey.CommentTree(commentToDistinguish.SubmissionID.Value), commentToDistinguish.ID, x => { x.IsDistinguished = commentToDistinguish.IsDistinguished; return(x); }, true);

                        Response.StatusCode = 200;
                        return(Json("Distinguish flag changed.", JsonRequestBehavior.AllowGet));
                    }
                }
            }

            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json("Unauthorized distinguish attempt.", JsonRequestBehavior.AllowGet));
        }