예제 #1
0
        public async Task <IActionResult> Add([FromForm] CreateSentPostDto createSentPostDto)
        {
            try
            {
                string createdFilePath = _fileService.CreateLocalFile(createSentPostDto.PhotoFile, PostPhotosFolder);

                var user = await _userManager.GetUserAsync(User);

                if (user == null)
                {
                    return(BadRequest());
                }

                createSentPostDto.AuthorId = user.Id;

                CreateSentPostViewModel createPostViewModel = CustomMapper.GetCreateSentPostViewModel(createSentPostDto, createdFilePath);
                var result = await _sentPostService.Add(createPostViewModel);

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

                return(BadRequest(result.Errors));
            }
            catch (IOException) { }

            return(BadRequest());
        }
예제 #2
0
 public static CreateSentPostViewModel GetCreateSentPostViewModel(CreateSentPostDto createPostDto, string photoPath)
 {
     return(new CreateSentPostViewModel(
                createPostDto.Title,
                createPostDto.Content,
                photoPath,
                createPostDto.BlogId,
                createPostDto.CategoryId,
                createPostDto.AuthorId));
 }