Example #1
0
        private void RefreshItems(SavedSearchesConfigFile savedSearches)
        {
            var searches = savedSearches
                           .OrderBy(s => s.Alias)
                           .Select(s => new SavedSearchModel(s, LoadItem, DeleteItem));

            using (SavedSearches.EnterMassUpdate())
            {
                SavedSearches.Clear();
                SavedSearches.AddRange(searches);
            }

            void LoadItem(SavedSearchModel item) =>
            _relay.Send(this, new SearchChangedMessage {
                SearchTags = item.Tags
            });

            async void DeleteItem(SavedSearchModel item)
            {
                var configs = SavedSearchConfigs;

                configs.Remove(item.Config);
                await SaveAndRefreshAsync(configs);
            }
        }
        public void Submit_PerformsCorrectRequest()
        {
            //setup
            var request = new RetrieveASavedSearchStub("DevKey", "api.careerbuilder.com", "", "", 12345, "savedSearchDID");

            //mock
            var response = new RestResponse <SavedSearches>
            {
                Data           = new SavedSearches(),
                ResponseStatus = ResponseStatus.Completed
            };
            var restReq = new Mock <IRestRequest>();

            var restClient = new Mock <IRestClient>();

            restClient.SetupSet(x => x.BaseUrl = "https://api.careerbuilder.com/CBAPI/SavedSearches/savedSearchDID");
            restClient.Setup(x => x.Execute <SavedSearches>(It.IsAny <IRestRequest>())).Returns(response);

            request.Request = restReq.Object;
            request.Client  = restClient.Object;

            //assertions

            SavedSearches rest = request.Submit("userOAuthToken");

            restReq.VerifyAll();
            restClient.VerifyAll();
        }
Example #3
0
        public async Task UpdateSavedSearches(bool forceUpdate = false)
        {
            if (UpdatingSavedSearches)
            {
                return;
            }

            if (!forceUpdate && _savedSearchesLastUpdate + TimeSpan.FromMinutes(15) > DateTime.Now &&
                _savedSearchesLastScreenName == Tokens.ScreenName)
            {
                return;
            }

            UpdatingSavedSearches = true;

            SavedSearchesScreenName = Tokens.ScreenName;

            SavedSearches.Clear();
            try
            {
                var savedSearches = await Tokens.SavedSearches.ListAsync();

                if (savedSearches.Count == 0)
                {
                    UpdatingSavedSearches = false;
                    return;
                }

                SavedSearches.Clear();
                foreach (var savedSearch in savedSearches)
                {
                    SavedSearches.Add(savedSearch);
                }

                _savedSearchesLastUpdate     = DateTime.Now;
                _savedSearchesLastScreenName = Tokens.ScreenName;
            }
            catch
            {
                UpdatingSavedSearches = false;
                return;
            }

            UpdatingSavedSearches = false;
        }
Example #4
0
        public IActionResult AddFilter(SavedSearches filter)
        {
            try
            {
                ReportingContext context = new ReportingContext();
                context.SavedSearches.Add(new SavedSearches {
                    UserId = filter.UserId, Field = filter.Field, Operator1 = filter.Operator1, Operator2 = filter.Operator2, Value1 = filter.Value1, Value2 = filter.Value2, IsPublic = filter.IsPublic, Searchname = filter.Searchname, Logic = filter.Logic
                });
                context.SaveChanges();

                //_context.SavedSearches.Add(new SavedSearches {UserId=filter.UserId, Field = filter.Field, Operator1 = filter.Operator1, Operator2 = filter.Operator2, Value1 = filter.Value1, Value2 = filter.Value2 });
                //_context.SaveChanges();
                return(Ok("Success"));
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }