コード例 #1
0
        public async Task <ResponseViewModel> GetSnippet(int id)
        {
            var snippet = await _snippetService.GetSnippetById(id);

            if (snippet == null)
            {
                return(_responseCreator.CreateFailure("Snippet not found!"));
            }

            var snippetViewModel = _mapper.Map <Snippet, SnippetViewModel>(snippet);

            snippetViewModel = _mapper.Map <User, SnippetViewModel>(await _userService.GetUserById(snippet.UserId), snippetViewModel);

            var tags = await _snippetService.GetTagsBySnippet(snippet);

            if (tags != null)
            {
                snippetViewModel.Tags = tags.Select(x => x.Content).ToArray();
            }

            snippetViewModel.Language = await _languageService.GetLanguageTextById(snippet.LanguageId);

            return(_responseCreator.CreateSuccess(snippetViewModel));
        }