예제 #1
0
        private bool CheckRemoved(bool removed)
        {
            var collection = Client.GetDatabase(DatabaseName).GetCollection <T>(CollectionName);

            List <T> reloadedItems = new List <T>();

            using (var cursor = collection.FindSync(Filter))
            {
                var countryList = cursor.ToList();
                foreach (var country in countryList)
                {
                    reloadedItems.Add(country);
                }
            }

            if (reloadedItems.Count != LoadedItems.Count)
            {
                removed = true;
                LoadedItems.Clear();
                foreach (var item in reloadedItems)
                {
                    LoadedItems.Add(item);
                }
            }

            return(removed);
        }
        /// <summary>
        /// Loads all the items from the database into the list.
        /// </summary>
        /// <param name="itemsRead">The items retrieved from the database.</param>
        private void LoadAllItemsFromDatabase(IMongoCollection <T> itemsRead)
        {
            LoadedItems.Clear();

            using (IAsyncCursor <T> cursor = itemsRead.FindSync(Filter))
            {
                List <T> itemList = cursor.ToList();
                foreach (T item in itemList)
                {
                    LoadedItems.Add(item);
                }
            }
        }
        /// <summary>
        /// Loads all the items from the database into the list.
        /// </summary>
        /// <param name="itemsRead">The items retrieved from the database.</param>
        private void LoadAllItemsFromDatabase(IMongoCollection <T> itemsRead)
        {
            LoadedItems.Clear();

            using (var cursor = itemsRead.FindSync(Filter))
            {
                var countryList = cursor.ToList();
                foreach (var country in countryList)
                {
                    LoadedItems.Add(country);
                }
            }
        }
        /// <summary>
        /// Gets the loaded items matching the database after an item has been removed.
        /// </summary>
        private void UpdateLoadedAfterRemove()
        {
            IMongoCollection <T> collection =
                Client.GetDatabase(DatabaseName).GetCollection <T>(CollectionName);

            List <T> reloadedItems = new List <T>();

            using (IAsyncCursor <T> cursor = collection.FindSync(Filter))
            {
                List <T> itemList = cursor.ToList();
                reloadedItems.AddRange(itemList);
            }

            if (reloadedItems.Count != LoadedItems.Count)
            {
                LoadedItems.Clear();
                foreach (T item in reloadedItems)
                {
                    LoadedItems.Add(item);
                }
            }
        }