Example #1
0
        /// <summary>
        /// Edits a given post
        /// </summary>
        /// <param name="actualRequest">the client request to be handled</param>
        /// <returns>the response to the given request</returns>
        private async Task <ActualRequest> UpdatePostAsync(ActualRequest actualRequest)
        {
            Request          request     = actualRequest.Request;
            PostShortVersion updatedPost = JsonSerializer.Deserialize <PostShortVersion>(request.Argument.ToString());
            bool             result      = await postRepo.EditPostAsync(updatedPost);

            Request responseRequest = new Request
            {
                ActionType = ActionType.POST_EDIT.ToString(),
                Argument   = JsonSerializer.Serialize(result)
            };

            if (!result)
            {
                return new ActualRequest {
                           Request = responseRequest,
                           Images  = null
                }
            }
            ;

            if (actualRequest.Images != null && actualRequest.Images.Any())
            {
                ImagesUtil.WriteImageToPath(actualRequest.Images[0], $"{FILE_PATH}/Posts", $"/{updatedPost.Id}.jpg");
            }
            return(new ActualRequest {
                Request = responseRequest,
                Images = null
            });
        }