Ejemplo n.º 1
0
        public FilterWindowViewModel()
        {
            ApplyCommand = new RelayCommand(ApplyCommandExecute);

            SearchCommand = new RelayCommand(SearchCommandExecute);

            ChooseCommand = new RelayCommand(ChooseCommandExecute, (obj) => _foundPeoples != null && _foundPeoples.Any());

            UseServer = StaticVkContractManager.UseServer;

            if (UseServer)
            {
                var contract = StaticVkContractManager.GetVkContractInstance();

                var allFilters = contract.GetAllSearchFilters();

                FixAllFilters(allFilters);

                AllFilters = new ObservableCollection <FilterModel>(allFilters);

                AllFilters.Insert(0, new FilterModel()
                {
                    Name = NewFilterNameConst
                });

                CurrentFilter = AllFilters.First();
            }
            else
            {
                CurrentFilter = new FilterModel();

                AllFilters = new ObservableCollection <FilterModel>();
            }
        }
Ejemplo n.º 2
0
        private void ApplyCommandExecute(object obj)
        {
            if (UseServer)
            {
                var contract = StaticVkContractManager.GetVkContractInstance();

                var toSendFilter = CurrentFilter.CopyFilter();

                if (!HasYears)
                {
                    toSendFilter.Years = null;
                }

                if (!HasSex)
                {
                    toSendFilter.Sex = default(Sex?);
                }

                if (!HasSubsCount || CurrentFilter.SubsCount == null || CurrentFilter.SubsCount == new IntervalValue <int>())
                {
                    toSendFilter.SubsCount = null;
                }

                if (!HasFamilyStatus)
                {
                    toSendFilter.FamilyStatus = default(MyFamilyStatus?);
                }

                if (!HasFriendsCount || CurrentFilter.FriendsCount == null || CurrentFilter.FriendsCount == new IntervalValue <int>())
                {
                    toSendFilter.FriendsCount = null;
                }

                if (toSendFilter.Name == NewFilterNameConst)
                {
                    contract.AddSearchFilter(toSendFilter, NewFilterName);
                }
                else
                {
                    contract.UpdateSearchFilter(toSendFilter);
                }
            }

            DialogResult = true;

            var window = obj as Window;

            if (window != null)
            {
                window.Close();
            }
        }