Exemple #1
0
        public async Task <CreateUpdatePostResponse> CreateAsync(CreateUpdatePostDto createdPost)
        {
            var uploadedfile = createdPost.PhotoFile;
            var documentDto  = new DocumentDto
            {
                FileName = uploadedfile.FileName,
                TypeFile = uploadedfile.GetType().ToString(),
                Url      = documentAppService.CreateDocumentUrl(uploadedfile)
            };
            var createdFile = await documentAppService.CreateAsync(documentDto);

            createdPost.PhotoPath = createdFile.Id.ToString();
            var result = await postAppService.CreatePost(createdPost);

            var response = new CreateUpdatePostResponse
            {
                postDto = null
            };

            if (result)
            {
                response.IsSuccess = true;
            }
            else
            {
                response.IsSuccess = false;
                response.Errors    = new string[] { "Create post failed!" };
            }
            return(response);
        }
Exemple #2
0
        public async Task <bool> CreatePost(CreateUpdatePostDto createdPost)
        {
            var isExistedTitlePost = await IsTitleExisted(createdPost.Title);

            if (isExistedTitlePost)
            {
                return(false);
            }
            createdPost.CreatedAt    = DateTime.Now;
            createdPost.CreationTime = DateTime.Now;
            await _postRepository.InsertAsync(ObjectMapper.Map <CreateUpdatePostDto, blog.Posts.Post>(createdPost));

            return(true);
        }
Exemple #3
0
        public async Task <CreateUpdatePostResponse> UpdateAsync(CreateUpdatePostDto updatedPost, Guid postId)
        {
            updatedPost.Id = postId;
            var result = await postAppService.UpdatePost(updatedPost);

            var response = new CreateUpdatePostResponse();

            response.postDto = updatedPost;
            if (result)
            {
                response.IsSuccess = true;
            }
            else
            {
                response.IsSuccess = false;
                response.Errors    = new string[] { "Update Fail!" };
            }
            return(response);
        }
Exemple #4
0
        public async Task <bool> UpdatePost(CreateUpdatePostDto updatedPostDto)
        {
            var isExistedId = await IsExistedPost(updatedPostDto.Id);

            if (!isExistedId)
            {
                return(false);
            }
            var post = await _postRepository.FirstOrDefaultAsync(x => x.Id == updatedPostDto.Id);

            //dùng mapper bị lỗi
            post.Title        = updatedPostDto.Title;
            post.Author       = updatedPostDto.Author;
            post.CategoryId   = updatedPostDto.CategoryId;
            post.Description  = updatedPostDto.Description;
            post.CreatedAt    = updatedPostDto.CreatedAt;
            post.CreationTime = updatedPostDto.CreationTime;
            post.PhotoPath    = updatedPostDto.PhotoPath;
            post.Content      = updatedPostDto.Content;

            await _postRepository.UpdateAsync(post);

            return(true);
        }