public async Task <BlogPostDto> Handle(GetBlogPostQuery query) { var postId = query.Id; var blogPost = await _blogRepository.GetBlogPostWithNoImages(postId); var postAsHtml = await _markdownService.ConvertToHtml(blogPost.Content); for (var i = 0; i < 20; i++) { var number = $"{i:00}"; var src = $"{number}.png"; var dest = $"/api/blog/{postId}/{number}"; postAsHtml = postAsHtml.Replace(src, dest); } return(new BlogPostDto { Id = postId, Date = DateTime.Now, Title = "Test title", Content = postAsHtml, Tags = _tagMapper.Map(blogPost.Tags).ToList() }); }
public async Task <List <TagModel> > GetTopBySearchTagAsync(string searchTag, int count) { List <TagModel> tagModels; using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { var tags = await uow.TagRepository.GetAll() .Where(t => t.Name.Contains(searchTag)) .OrderBy(t => t.Name.IndexOf(searchTag)) .ThenBy(t => t.Name) .Take(count) .ToListAsync(); tagModels = tags.Select(t => tagMapper.Map(t)).ToList(); } return(tagModels); }
public BlogPostHeaderDto Map(BlogPostHeader p) { return(new BlogPostHeaderDto { Id = p.Id, Title = p.Title, Text = p.Header, Published = p.PublishingDate, Tags = _tagMapper.Map(p.Tags).ToList() }); }
public List <WordTranslationModel> Post(List <WordTranslationImportModel> wordTranslations) { List <WordTranslationModel> wordTranslationsToReturn = new List <WordTranslationModel>(); foreach (WordTranslationImportModel wordTranslation in wordTranslations) { wordTranslation.OriginalWordId = wordService.Exists(wordTranslation.OriginalWord, wordTranslation.LanguageId); if (wordTranslation.OriginalWordId == 0) { wordTranslation.OriginalWordId = wordService.Add(wordMapper.ToDomainModel(new WordModel() { Value = wordTranslation.OriginalWord, LanguageId = wordTranslation.LanguageId, Transcription = wordTranslation.Transcription, Description = wordTranslation.Description })); } wordTranslation.TranslationWordId = wordService.Exists(wordTranslation.TranslationWord, TranslationLanguageId); if (wordTranslation.TranslationWordId == 0) { wordTranslation.TranslationWordId = wordService.Add(wordMapper.ToDomainModel(new WordModel() { Value = wordTranslation.TranslationWord, LanguageId = TranslationLanguageId })); } foreach (TagModel tag in wordTranslation.Tags) { tag.Id = tagService.Exists(tag.Name); if (tag.Id == 0) { tag.Id = tagService.Add(tagMapper.Map(tag)); } } wordTranslation.OwnerId = UserId; int wordTranslationId = wordTranslationService.Add(wordTranslationMapper.Map(wordTranslation, tagMapper.MapRange(wordTranslation.Tags))); wordTranslationsToReturn.Add(new WordTranslationModel() { Id = wordTranslationId, OriginalWord = wordTranslation.OriginalWord, TranslationWord = wordTranslation.TranslationWord }); } return(wordTranslationsToReturn); }
public async Task Execute(UploadBlogPostCommand command) { var postFile = command.Files.FirstOrDefault(f => f.FileName.EndsWith(".md")); var imageFiles = command.Files.Where(f => !f.FileName.EndsWith(".md")); var postFileContent = Encoding.UTF8.GetString(postFile.Data, 0, postFile.Data.Length); var processingMetadataResult = _postMetadataResolver.Resolve(postFileContent); var metadata = processingMetadataResult.Result; var date = metadata.PublishedDate ?? DateTime.Now; var postId = metadata.Id; var tags = _tagMapper.Map(metadata.Categories?.ToArray()); var blogPost = new BlogPost { Id = postId, Title = metadata.Title, Content = postFileContent, Header = metadata.Header, PublishingDate = date, Status = (metadata.PostType == BlogPostMetadata.PostTypeEnum.Article) ? BlogStatusTypeEnum.Active : BlogStatusTypeEnum.Page, Images = new List <BlogPostImage>(), Tags = tags }; foreach (var imageFile in imageFiles) { var fileName = Path.GetFileNameWithoutExtension(imageFile.FileName); var blogPostImage = new BlogPostImage { Id = fileName, Data = imageFile.Data }; blogPost.Images.Add(blogPostImage); } var existingPost = await _blogRepository.GetBlogPostWithNoImages(postId); var isPostExists = existingPost != null; if (isPostExists) { await _blogRepository.DeleteBlogPost(postId); } await _blogRepository.Add(blogPost); }
public async Task <WordTranslationFullModel> GetWordFullInformationAsync(string word, int originalLangId, int translationLangId) { WordTranslationFullModel infoWord = new WordTranslationFullModel { OriginalWord = word }; using (var uow = unitOfWorkFactory.GetUnitOfWork()) { Word origWord = await uow.WordRepository.GetAll() .Where(w => w.Value == word && w.LanguageId == originalLangId) .FirstOrDefaultAsync(); infoWord.Id = origWord.Id; infoWord.Description = origWord.Description; infoWord.Transcription = origWord.Transcription; infoWord.PartOfSpeechId = origWord.PartOfSpeechId; infoWord.Comment = origWord.Comment; if (await GetAmountOfTranslations(origWord.Id, translationLangId) > 0) { List <Word> translations = await uow.WordTranslationRepository.GetAll() .Where(x => x.OriginalWord.Value == word && x.OriginalWord.LanguageId == originalLangId && x.TranslationWord.LanguageId == translationLangId) .Select(x => x.TranslationWord) .ToListAsync(); infoWord.Translations = translations.Select(x => wordMapper.ToValueModel(x)).ToList(); } if (await GetAmountOfTranslations(origWord.Id, originalLangId) > 0) { List <Word> synonims = await uow.WordTranslationRepository.GetAll() .Where(x => x.OriginalWord.Value == word && x.OriginalWord.LanguageId == originalLangId && x.TranslationWord.LanguageId == originalLangId) .Select(x => x.TranslationWord) .ToListAsync(); infoWord.Synonims = synonims.Select(x => wordMapper.ToValueModel(x)).ToList(); } if (origWord.Tags.Count > 0) { List <Tag> tags = origWord.Tags.ToList(); infoWord.Tags = tags.Select(x => tagMapper.Map(x)).ToList(); } } return(infoWord); }