Пример #1
0
        private IReadOnlyCollection <DataSetValuePair> UpdateDatasetSource()
        {
            var cases = ViewModelLocatorStatic.Locator.CaseModule.Cases;

            LoadDataSet(cases);

            if (SelectedMonth != null)
            {
                if (SelectedMonth == "All")
                {
                    var filteredcases = cases;
                    cases = new ObservableCollection <CaseModel>(filteredcases);
                }

                else
                {
                    var monthSelected = MonthOptions.IndexOf(SelectedMonth);
                    var filteredcases = cases.Where(f => f.Model.CaseHearingDate?.Month == monthSelected);
                    cases = new ObservableCollection <CaseModel>(filteredcases);
                }

                LoadDataSet(cases);
            }

            if (SelectedYear != null)
            {
                var year = 0;
                try
                {
                    year = Convert.ToInt32(SelectedYear);
                }
                catch (Exception e)
                {
                    year = DateTime.Now.Year;
                }

                var filteredcases = cases.Where(f => f.Model.CaseHearingDate?.Year == year);
                cases = new ObservableCollection <CaseModel>(filteredcases);
                LoadDataSet(cases);
            }

            if (Day != null)
            {
                var filteredcases = cases.Where(f => f.Model.CaseHearingDate?.Day == Day);
                cases = new ObservableCollection <CaseModel>(filteredcases);
                LoadDataSet(cases);
            }

            if (SelectedStatus != null)
            {
                if (SelectedStatus == "All")
                {
                    var filteredcases = cases;
                    cases = new ObservableCollection <CaseModel>(filteredcases);
                    LoadDataSet(cases);
                }

                else
                {
                    var filteredpersons = cases.Where(f => f.Model.CaseStatus == SelectedStatus);
                    cases = new ObservableCollection <CaseModel>(filteredpersons);
                    LoadDataSet(cases);
                }
            }

            //            if (Respondent != null)
            //            {
            //                var r = Respondent.ToLowerInvariant();
            //                var filteredpersons =
            //                    cases.Where(f => f.Respondent.Model.FirstName.ToLowerInvariant().Contains(r) ||
            //                    f.Respondent.Model.LastName.ToLowerInvariant().Contains(r)
            //                    );
            //                cases = new ObservableCollection<CaseModel>(filteredpersons);
            //                LoadDataSet(cases);
            //            }

            if (!string.IsNullOrWhiteSpace(Respondent) || !string.IsNullOrEmpty(Respondent))
            {
                try
                {
                    var personCollection = new ObservableCollection <CaseModel>();

                    foreach (var person in cases)
                    {
                        if (!string.IsNullOrWhiteSpace(person.Respondent.ToString()) || !string.IsNullOrEmpty(person.Respondent.ToString()))
                        {
                            if (person.Respondent.Model.FirstName.ToLowerInvariant().Contains(Respondent.ToLowerInvariant()))
                            {
                                personCollection.Add(person);
                            }
                        }
                    }

                    cases = new ObservableCollection <CaseModel>(personCollection);
                    LoadDataSet(cases);
                }
                catch (Exception e) { }
            }

            _sources.Add(new DataSetValuePair("CaseDataSet", _casesDataSet.Where(c => TitleFilter != null && c.CaseId.ToLowerInvariant().Contains(TitleFilter.ToLowerInvariant()) || c.CaseName.ToLowerInvariant().Contains(TitleFilter.ToLowerInvariant()))));
            return(_sources);
        }