Пример #1
0
        /// <summary>
        /// Извлекаем пост для редактирования
        /// </summary>
        /// <param name="postId"></param>
        public async Task <DtoPostEdit> GetFromDbAsync(int postId)
        {
            var post = await _repoPosts.GetPostByIdAsync(postId);

            var authors = await _repoAuthors.GetAuthorsByExtIdAsync(post.AuthorExternalId);

            var editPost = _mapper.Map <DtoPostEdit>(post);

            editPost.Authors = _mapper.Map <List <DtoAuthorEdit> >(authors);
            return(editPost);
        }
Пример #2
0
        /// <summary>
        /// Логика редактирования поста
        /// </summary>
        /// <param name="postEdit"></param>
        public async Task EditPostAsync(DtoPostEdit postEdit)
        {
            var post = await _repoPosts.GetPostByIdAsync(postEdit.Id);

            var authors = await _repoAuthors.GetAuthorsByExtIdAsync(post.AuthorExternalId);

            _mapper.Map(postEdit, post);
            var mappedAuthors = authors.CustomMap(postEdit.Authors);

            await _repoAuthors.UpdateAuthorsRangeAsync(mappedAuthors);

            await _repoPosts.UpdatePostAsync(post);

            await _servPosts.UpdatePostsCashAsync();

            await _servPosts.UpdatePostsFiltersCashAsync();
        }