public int CopyDictionary(int dictionaryId, int userId) { var translations = TranslationsRepository.GetTranslationsForDictionary(dictionaryId).ToList(); var dictionary = DictionariesRepository.GetById(dictionaryId); Context.Entry(dictionary).State = EntityState.Detached; dictionary.Id = 0; dictionary.UserId = userId; dictionary.ParentDictionaryId = dictionaryId; dictionary.User = null; dictionary.Date = DateTime.Today; dictionary.IsPublic = false; DictionariesRepository.Insert(dictionary); DictionariesRepository.Save(); translations.ForEach(translation => { Context.Entry(translation).State = EntityState.Detached; translation.Id = 0; translation.DictionaryId = dictionary.Id; translation.Dictionary = null; }); var check = TranslationsRepository.Insert(translations) && TranslationsRepository.Save(); return(check ? dictionary.Id : -1); }
public bool UpdateDictionary(int dictionaryId) { var dictionary = DictionariesRepository.GetById(dictionaryId); if (dictionary.ParentDictionaryId == null) { return(false); } var currentTranslations = TranslationsRepository.GetTranslationsForDictionary(dictionaryId).ToList(); var parentTranslations = TranslationsRepository.GetTranslationsForDictionary(dictionary.ParentDictionaryId.Value).ToList(); var toAdd = parentTranslations.Except(currentTranslations).ToList(); toAdd.ForEach(trans => { var translation = new Translation { DictionaryId = dictionaryId, FirstLangWord = trans.FirstLangWord, SecondLangWord = trans.SecondLangWord }; TranslationsRepository.Insert(translation); }); return(TranslationsRepository.Save());; }
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)); }
public IList <Translation> GetDictionaryTranslations(int dictionaryId) { return(TranslationsRepository.GetTranslationsForDictionary(dictionaryId).ToList()); }