예제 #1
0
        public ActionResult EditSnippet(int id)
        {
            EditSnippetViewModel EditSnippetModel = new EditSnippetViewModel();

            EditSnippetModel.Snippet    = _snippetService.GetSnippetById(id);
            EditSnippetModel.Operations = _snippetService.GetAllOperations();
            EditSnippetModel.Groups     = _groupService.GetAllGroups();
            return(View(EditSnippetModel));
        }
        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));
        }