Example #1
0
        public async Task <IActionResult> Update([FromForm] UpdatePostDto updatePostDto)
        {
            UpdatePostViewModel updatePostViewModel = CustomMapper.GetUpdatePostViewModel(updatePostDto);

            if (updatePostDto.PhotoFile != null)
            {
                var post = await _postService.GetById(updatePostDto.Id);

                string existingFilePath = post.HeaderPhotoPath;

                try
                {
                    _fileService.UpdateLocalFile(updatePostDto.PhotoFile, existingFilePath);
                }
                catch (IOException) { }
            }

            var result = await _postService.Update(updatePostViewModel);

            if (result.IsValid)
            {
                return(Ok());
            }

            return(BadRequest(result.Errors));
        }