Example #1
0
        public void updatePopularWords()
        {
            //добавление новых слов из template в язык
            var templatesId    = dbContext.Template.Select(t => t.TemplateId).ToList();
            var popularWordsId = dbContext.PopularWords.Select(t => t.WordId).ToList();

            foreach (var template in templatesId)
            {
                if (!popularWordsId.Contains(template))
                {
                    PopularWord popularWord = new PopularWord();
                    popularWord.WordId      = template;
                    popularWord.Description = dbContext.Template.Find(template).Description;
                    popularWord.Count       = 0;
                    dbContext.PopularWords.Add(popularWord);
                }
            }
            //dbContext.SaveChanges();
            //удаление неиспользуемых слов
            foreach (var popularWord in popularWordsId)
            {
                if (!templatesId.Contains(popularWord))
                {
                    PopularWord deletePopularWord = dbContext.PopularWords.Find(popularWord);
                    dbContext.Entry(deletePopularWord).State = EntityState.Deleted;
                }
            }
            dbContext.SaveChanges();
        }
Example #2
0
        private SourceWithTranslation Create(WordWithTranslation wordWithTranslation, int type)
        {
            SourceWithTranslation result = null;

            Adapter.ActionByContext(context => {
                var popularWord = new PopularWord
                {
                    WordTranslationId = wordWithTranslation.Id, Type = type
                };
                context.PopularWord.Add(popularWord);
                context.SaveChanges();
                if (IdValidator.IsValid(popularWord.Id))
                {
                    result = new SourceWithTranslation();
                    result.Set(popularWord.Id, wordWithTranslation.Source, wordWithTranslation.Translations[0]);
                }
            });
            return(result);
        }