Ejemplo n.º 1
0
        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)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates a thread
        /// </summary>
        /// <remarks>
        /// The user must be the owner of the thread to update it, and only the locked status of the thread can be changed
        /// </remarks>
        /// <param name="id">The id of the thread to update</param>
        /// <param name="request">The update information of the request</param>
        /// <returns></returns>
        public async Task <Result <ApiThread> > UpdateThread(int id, UpdateThreadRequest request)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>()
            {
                { "id", id.ToString() }
            };

            if (request.Locked != null)
            {
                parameters.Add("locked", request.Locked.ToString());
            }

            HttpResponseMessage response = await _requestsClient.SendRequest(Endpoints.UpdateThread, parameters)
                                           .ConfigureAwait(false);

            return(await ResponseParser.ParseJsonResponse <ApiThread>(response).ConfigureAwait(false));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Update(int id, [FromBody] UpdateThreadRequest threadRequest)
        {
            Thread thr    = _threadRepository.Find(id);
            bool   admin  = HttpContext.User.Claims.FirstOrDefault(claim => claim.Type == "Admin").Value == "True";
            int    userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(claim => claim.Type == "Id").Value);

            if (thr != null && (thr.UserId == userId || admin))
            {
                thr.Body = threadRequest.Body;
                _threadRepository.Update(thr);
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            else
            {
                return(Unauthorized());
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> UpdateThread(int id, UpdateThreadRequest request)
        {
            // Requests the thread, returning if not authorized
            Thread thread = await _repository.GetThreadAsync(id);

            int userID = Tools.GetUserID(User);

            if (thread.UserID != userID)
            {
                return(Unauthorized());
            }

            // Updates thread and returns
            if (request.Locked != null && thread.LockedBy != "Admin")
            {
                thread.LockedBy = (bool)request.Locked ? "User" : null;
                thread.Locked   = (bool)request.Locked;
            }
            await _repository.SaveChangesAsync();

            return(Json(new ApiThread(thread)));
        }