Exemplo n.º 1
0
        public MemoryStream ExportDictionary(int dictionaryId)
        {
            var dictionary           = DictionariesRepository.GetById(dictionaryId);
            var translations         = TranslationsRepository.GetTranslationsForDictionary(dictionaryId);
            var translationPairsList = new List <TranslationPair>();

            translationPairsList.Add(new TranslationPair
            {
                FirstLanguageWord  = dictionary.FirstLanguage.Name,
                SecondLanguageWord = dictionary.SecondLanguage.Name
            });
            foreach (var translation in translations)
            {
                translationPairsList.Add(new TranslationPair
                {
                    FirstLanguageWord  = translation.FirstLangWord,
                    SecondLanguageWord = translation.SecondLangWord
                });
            }
            return(CsvService.CreateCsv(translationPairsList));
        }
Exemplo n.º 2
0
 public bool ImportDictionary(MemoryStream csv, int dictionaryId)
 {
     try
     {
         var list  = CsvService.FormatCsv(csv);
         var toAdd = new List <Translation>();
         foreach (TranslationPair translationPair in list)
         {
             toAdd.Add(new Translation
             {
                 DictionaryId   = dictionaryId,
                 FirstLangWord  = translationPair.FirstLanguageWord,
                 SecondLangWord = translationPair.SecondLanguageWord
             });
         }
         TranslationsRepository.Insert(toAdd);
         TranslationsRepository.Save();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }