Beispiel #1
0
        /// <summary>
        /// Methods
        /// </summary>

        private void PerformFiltering()
        {
            if (_filter == null)
            {
                _filter = string.Empty;
            }

            var lowerCaseFilter = Filter.ToLowerInvariant().Trim();

            var result =
                _allCustomers.Where(d => d.FullName.ToLowerInvariant().Contains(lowerCaseFilter)).ToList();

            var toRemove = CustomerList.Except(result).ToList();

            foreach (var x in toRemove)
            {
                CustomerList.Remove(x);
            }

            var resultCount = result.Count;

            for (int i = 0; i < resultCount; i++)
            {
                var resultItem = result[i];
                if (i + 1 > CustomerList.Count || !CustomerList[i].Equals(resultItem))
                {
                    CustomerList.Insert(i, resultItem);
                }
            }
        }