public ActionResult Download(UserLanguages userLanguages, string group, DocumentType type) { if (UserLanguages.IsInvalid(userLanguages)) { return(RedirectToAction("Index", RouteConfig.GROUPS_BY_COMPARISONS_CONTROLLER)); } ComparisonForUser comparisonForUser = GetComparisonForUser(userLanguages, group); if (comparisonForUser == null) { return(RedirectToActionPermanent("Index", RouteConfig.GROUPS_BY_COMPARISONS_CONTROLLER)); } var downloader = new ComparisonDownloader(WebSettingsConfig.Instance.DomainWithProtocol, CommonConstants.GetFontPath(Server)); var documentGenerator = downloader.Download(type, comparisonForUser.Title, comparisonForUser); return(File(documentGenerator.Generate(), documentGenerator.ContentType, documentGenerator.FileName)); }
private DocumentationGenerator GetGenerator(AllMaterialsQuery allMaterialsQuery, SectionId sectionId, long id, string title) { DocumentationGenerator result; switch (sectionId) { case SectionId.GroupByWords: var groupWordsDownloader = new GroupDataDownloader(_domain, _fontPath) { Header = string.Format("Слова на тему «{0}»", title), TableHeader = "Слово" }; List <SourceWithTranslation> words = allMaterialsQuery.GetWordsByGroup(id); result = groupWordsDownloader.Download(DOCUMENT_TYPE, title, words); break; case SectionId.GroupByPhrases: var groupDataDownloader = new GroupDataDownloader(_domain, _fontPath) { Header = string.Format("Фразы на тему «{0}»", title), TableHeader = "Фраза" }; List <SourceWithTranslation> sentences = allMaterialsQuery.GetSentencesByGroup(id); result = groupDataDownloader.Download(DOCUMENT_TYPE, title, sentences); break; case SectionId.VisualDictionary: var visualDictionaryDownloader = new VisualDictionaryDownloader(_domain, _fontPath); RepresentationForUser representationForUser = allMaterialsQuery.GetVisualDictionary(title); result = visualDictionaryDownloader.Download(DOCUMENT_TYPE, title, representationForUser); break; case SectionId.FillDifference: var comparisonDownloader = new ComparisonDownloader(_domain, _fontPath); ComparisonForUser comparisonForUser = allMaterialsQuery.GetComparison(title); result = comparisonDownloader.Download(DOCUMENT_TYPE, title, comparisonForUser); break; case SectionId.Video: var videoTextDownloader = new VideoTextDownloader(_domain, _fontPath); VideoForUser videoForUser = allMaterialsQuery.GetVideo(title); result = videoTextDownloader.Download(DOCUMENT_TYPE, title, videoForUser); break; case SectionId.PopularWord: var popularWordsDownloader = new PopularWordsDownloader(_domain, _fontPath) { Header = "Минилекс слов Гуннемарка" }; List <SourceWithTranslation> popularWords = allMaterialsQuery.GetPopularWords(); result = popularWordsDownloader.Download(DOCUMENT_TYPE, title, popularWords); break; default: result = null; break; } return(result); }