public void Search(string searchTerm, string searchField, bool?searchDefault, int?limit) { List <SampleData> _searchResults; _searchResults = (string.IsNullOrEmpty(searchField) ? LuceneSearch.Search(searchTerm) : LuceneSearch.Search(searchTerm, searchField)).ToList(); if (string.IsNullOrEmpty(searchTerm) && !_searchResults.Any()) { _searchResults = LuceneSearch.GetAllIndexRecords().ToList(); } // limit display number of database records var limitDb = limit == null ? 3 : Convert.ToInt32(limit); List <SampleData> allSampleData; if (limitDb > 0) { allSampleData = SampleDataRepository.GetAll().ToList().Take(limitDb).ToList(); } else { allSampleData = SampleDataRepository.GetAll(); } var AllSampleData = allSampleData; var SearchIndexData = _searchResults; }
public ActionResult UpdateIndex() { LuceneSearch.ClearLuceneIndex(); var x = SampleDataRepository.GetAll(); LuceneSearch.AddUpdateLuceneIndex(x); return(RedirectToAction("Index")); }
public void Delete() { var repository = new SampleDataRepository(); var controller = new CompaniesController(repository); int id = 1; controller.DeleteCompany(id); Assert.IsNull(repository.Get(id)); }
private DefaultViewModel getDefaultViewModel(string searchTerm, string searchField, string type = "") { // create default Lucene search index directory if (!Directory.Exists(GoLucene._luceneDir)) { Directory.CreateDirectory(GoLucene._luceneDir); } // perform Lucene search IEnumerable <SampleData> searchResults = new List <SampleData>(); if (string.IsNullOrEmpty(type)) { searchResults = string.IsNullOrEmpty(searchField) ? GoLucene.Search(searchTerm) : GoLucene.Search(searchTerm, searchField); } else if (type == "default") { searchResults = string.IsNullOrEmpty(searchField) ? GoLucene.SearchDefault(searchTerm) : GoLucene.SearchDefault(searchTerm, searchField); } // setup and return view model var search_field_list = new List <SelectedList> { new SelectedList { Text = "(All Fields)", Value = "" }, new SelectedList { Text = "Id", Value = "Id" }, new SelectedList { Text = "Name", Value = "Name" }, new SelectedList { Text = "Description", Value = "Description" } }; return(new DefaultViewModel { AllSampleData = SampleDataRepository.GetAll(), AllSearchIndexData = GoLucene.GetAllIndexRecords(), SampleData = new SampleData { Id = 9, Name = "El-Paso", Description = "City in Texas" }, SampleSearchResults = searchResults, SearchFieldList = search_field_list, }); }
public void Post() { Company company = new Company { Id = 5, Name = "Testing1", PIN = "92727475465" }; HttpConfiguration config = new HttpConfiguration(); WebApiConfig.Register(config); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost"); request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; var repository = new SampleDataRepository(); var controller = new CompaniesController(repository) { Request = request }; HttpResponseMessage response = controller.PostCompany(company); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); Assert.IsNotNull(response.Headers.Location); Company newCompany = response.Content.ReadAsAsync<Company>().Result; Assert.IsNotNull(newCompany); }
public void Post() { Company company = new Company { Id = 5, Name = "Testing1", PIN = "92727475465" }; HttpConfiguration config = new HttpConfiguration(); WebApiConfig.Register(config); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost"); request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; var repository = new SampleDataRepository(); var controller = new CompaniesController(repository) { Request = request }; HttpResponseMessage response = controller.PostCompany(company); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); Assert.IsNotNull(response.Headers.Location); Company newCompany = response.Content.ReadAsAsync <Company>().Result; Assert.IsNotNull(newCompany); }
public ActionResult CreateIndex() { GoLucene.AddUpdateLuceneIndex(SampleDataRepository.GetAll()); TempData["Result"] = "Search index was created successfully!"; return(RedirectToAction("Index")); }
public ActionResult Index (string searchTerm, string searchField, bool?searchDefault, int?limit) { // create default Lucene search index directory if (!Directory.Exists(GoLucene._luceneDir)) { Directory.CreateDirectory(GoLucene._luceneDir); } // perform Lucene search List <SampleData> _searchResults; if (searchDefault == true) { _searchResults = (string.IsNullOrEmpty(searchField) ? GoLucene.SearchDefault(searchTerm) : GoLucene.SearchDefault(searchTerm, searchField)).ToList(); } else { _searchResults = (string.IsNullOrEmpty(searchField) ? GoLucene.Search(searchTerm) : GoLucene.Search(searchTerm, searchField)).ToList(); } if (string.IsNullOrEmpty(searchTerm) && !_searchResults.Any()) { _searchResults = GoLucene.GetAllIndexRecords().ToList(); } // setup and return view model var search_field_list = new List <SelectedList> { new SelectedList { Text = "(All Fields)", Value = "" }, new SelectedList { Text = "Id", Value = "Id" }, new SelectedList { Text = "Name", Value = "Name" }, new SelectedList { Text = "Description", Value = "Description" } }; // limit display number of database records var limitDb = limit == null ? 3 : Convert.ToInt32(limit); List <SampleData> allSampleData; if (limitDb > 0) { allSampleData = SampleDataRepository.GetAll().ToList().Take(limitDb).ToList(); ViewBag.Limit = SampleDataRepository.GetAll().Count - limitDb; } else { allSampleData = SampleDataRepository.GetAll(); } return(View(new IndexViewModel { AllSampleData = allSampleData, SearchIndexData = _searchResults, SampleData = new SampleData { Id = 9, Name = "El-Paso", Description = "City in Texas" }, SearchFieldList = search_field_list, })); }
protected static List<ICustomerVM> CreateFamousCustomerVMs() { var dataRepo = new SampleDataRepository(); List<Customer> customers = dataRepo.GetAllCustomers(); return new List<ICustomerVM>(customers.Select(customer => new FakeCustomerVM {BackingCustomer = customer})); }
private void createIndex() { GoLucene.AddUpdateLuceneIndex(SampleDataRepository.GetAll()); litResult.Text = "Search index was created successfully!"; bindData(); }
public void CreateIndex() { LuceneSearch.AddUpdateLuceneIndex(SampleDataRepository.GetAll()); }
public StudentBL() { _repo = new SampleDataRepository(); }
public SampleSessionData() { sampleRepo = new SampleDataRepository(); Customer = new CustomerVM(sampleRepo); }