public void Find() { //если выбран определенный город, то фильтрую лимиты и клиентов if (CityForFind != null && CityForFind?.Id != AllCity.Id) { Clients.Clear(); var listClients = Client.AllClients .Where(c => string.IsNullOrEmpty(LastName) || c.LastName.Contains(LastName, StringComparison.InvariantCultureIgnoreCase)) .Where(c => CityForFind == null || CityForFind.Id == AllCity.Id || c.City.Id == CityForFind.Id).ToList(); foreach (var c in listClients) { Clients.Add(c); } SelectedClient = null; Limits.Clear(); var listLimits = MeasurementLimit.AllMeasurementLimits .Where(m => CityForFind == null || CityForFind.Id == AllCity.Id || m.City.Id == CityForFind.Id).ToList(); foreach (var m in listLimits) { Limits.Add(m); } SelectedLimit = null; MeasurementsWithoutDate.Clear(); MeasurementsWithDate.Clear(); var listMeasure = Measurement.AllMeasurements .Where(m => CityForFind == null || CityForFind.Id == AllCity.Id || m.MeasurementLimit.City.Id == CityForFind.Id).ToList(); foreach (var m in listMeasure) { //формирую списки для показа с назначенными замерами датам и без дат if (m.MeasurementDate == null || DateTime.Equals(m.MeasurementDate, DateTime.MinValue)) { MeasurementsWithoutDate.Add(m); } else { MeasurementsWithDate.Add(m); } } StayLimits = GetCountStayLimits(); } //если не выбран определенный город else { MeasurementsWithoutDate.Clear(); MeasurementsWithDate.Clear(); Clients.Clear(); foreach (var c in Client.AllClients) { Clients.Add(c); } SelectedClient = null; Limits.Clear(); foreach (var m in MeasurementLimit.AllMeasurementLimits) { Limits.Add(m); } SelectedLimit = null; foreach (var m in Measurement.AllMeasurements) { //формирую списки для показа с назначенными замерами датам и без дат if (m.MeasurementDate == null || DateTime.Equals(m.MeasurementDate, DateTime.MinValue)) { MeasurementsWithoutDate.Add(m); } else { MeasurementsWithDate.Add(m); } } StayLimits = null; } }