Exemple #1
0
        public ActionResult Lock(PostLockInputModel input)
        {
            if (input != null && this.ModelState.IsValid)
            {
                var post = this.Data.Posts.GetById(input.PostId);
                if (post == null || post.IsDeleted)
                {
                    return(this.HttpNotFound());
                }

                var userId = this.User.Identity.GetUserId();
                if (post.AuthorId != userId && !this.User.IsModerator() && !this.User.IsAdmin())
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                post.LockReason = input.LockReason;
                post.LockedById = userId;
                post.IsLocked   = true;

                this.Data.Posts.Update(post);
                this.Data.SaveChanges();

                return(this.RedirectToAction("Details", "Posts", new { area = string.Empty, id = post.Id }));
            }

            return(this.JsonError("Reason is required"));
        }
Exemple #2
0
        public ActionResult Lock(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var post = this.Data.Posts.GetById(id);

            if (post == null || post.IsDeleted)
            {
                return(this.HttpNotFound());
            }

            var userId = this.User.Identity.GetUserId();

            if (post.AuthorId != userId && !this.User.IsModerator() && !this.User.IsAdmin())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var model = new PostLockInputModel {
                PostId = post.Id
            };

            return(this.PartialView(model));
        }