Exemplo n.º 1
0
        /// <summary>
        /// Returns all site words in storage
        /// </summary>
        /// <returns>List of site words</returns>
        private List <SiteWord> getSiteWords()
        {
            List <SiteWord> words = new List <SiteWord>();

            using (SiteWordContext context = new SiteWordContext())
            {
                words = context.SiteWords.OrderByDescending(siteWord => siteWord.Count).ToList();
            }
            return(words);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Stores the passed site words, when passed sie word already exists in storage the record will be updated
        /// </summary>
        /// <param name="words">List of site words</param>
        private void storeSiteWords(List <SiteWord> words)
        {
            using (SiteWordContext context = new SiteWordContext())
            {
                var wordIds         = words.Select(word => word.Id);
                var existingWordIds = new HashSet <string>(
                    context.SiteWords.Where(x => wordIds.Contains(x.Id)).Select(x => x.Id));

                foreach (SiteWord word in words)
                {
                    if (existingWordIds.Contains(word.Id))
                    {
                        context.Update(word);
                    }
                    else
                    {
                        context.SiteWords.Add(word);
                    }
                }

                context.SaveChanges();
            }
        }