public async Task <IActionResult> GetThread(int id)
        {
            Thread thread = await _repository.GetThreadAsync(id);

            if (thread == null)
            {
                return(NotFound("Requested thread not found"));
            }
            if (thread.Deleted || thread.User.Deleted)
            {
                return(Gone("Thread deleted"));
            }

            return(Json(new ApiThread(thread)));
        }
        // Returns a page of the requested thread
        public async Task <IActionResult> Index(int id, int page = 1)
        {
            // Retrieves the requested thread
            Thread thread = await _repository.GetThreadAsync(id);

            // Returns 404 if thread is null
            if (thread == null)
            {
                return(NotFound());
            }

            // Returns message of thread has been removed
            if (thread.Deleted || thread.User.Deleted)
            {
                MessageViewModel messageModel = new MessageViewModel()
                {
                    Title        = "Removed",
                    MessageTitle = "This thread has been removed"
                };
                return(View("Message", messageModel));
            }

            // Sets the current user
            User user = await _repository.GetUserAsync(User);

            // Retrieves comments for the requested page
            Result <IEnumerable <Comment> > result = _repository.GetThreadReplies(thread, page);

            if (result.Failure)
            {
                return(StatusCode(result.Code));
            }

            // Creates model and returns view
            ThreadViewModel model = new ThreadViewModel()
            {
                Thread    = thread,
                Comments  = result.Value,
                Page      = page,
                PageCount = ((thread.Comments.Count + 1) + (PostsPerPage - 1)) / PostsPerPage,
                User      = user
            };

            return(View("Thread", model));
        }
        public async Task <IActionResult> AdminUpdate(int id, UpdateThreadRequest request)
        {
            // Retrieves thread and updates information
            Thread thread = await _repository.GetThreadAsync(id);

            thread.Pinned = request.Pinned ?? thread.Pinned;
            thread.Locked = request.Locked ?? thread.Locked;
            await _repository.SaveChangesAsync();

            // Returns response
            return(Json(new ApiThread(thread)));
        }