Begin adding fluxnet site autocomplete

This commit is contained in:
2016-01-29 12:40:00 -05:00
parent 7e4d475260
commit c5fcb8d635
5 changed files with 47 additions and 6 deletions
+11 -1
View File
@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.Entity; using System.Data.Entity;
using System.Linq;
using LeafWeb.Core.Models; using LeafWeb.Core.Models;
namespace LeafWeb.Core.DAL namespace LeafWeb.Core.DAL
@@ -22,10 +23,19 @@ namespace LeafWeb.Core.DAL
#region Fluxnet Sites #region Fluxnet Sites
public IEnumerable<FluxnetSite> GetFluxnetSites() public IQueryable<FluxnetSite> GetFluxnetSites()
{ {
return _db.FluxnetSites; return _db.FluxnetSites;
} }
public IQueryable<FluxnetSite> GetFluxnetSitesAutocomplete(string term)
{
return
from fs in GetFluxnetSites()
where fs.FluxnetId.StartsWith(term)
|| fs.SiteName.Contains(term)
select fs;
}
#endregion #endregion
} }
} }
+21
View File
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LeafWeb.Core.DAL;
namespace LeafWeb.Web.Controllers
{
//[UserActivity]
public class ControllerBase : Controller
{
protected readonly DataService DataService = new DataService();
protected override void Dispose(bool disposing)
{
DataService.Dispose();
base.Dispose(disposing);
}
}
}
+14
View File
@@ -0,0 +1,14 @@
using System.Web.Mvc;
using LeafWeb.Core.DAL;
namespace LeafWeb.Web.Controllers
{
public class FluxnetSiteController : ControllerBase
{
public JsonResult Autocomplete(string term)
{
var cities = DataService.GetFluxnetSitesAutocomplete(term);
return Json(cities, JsonRequestBehavior.AllowGet);
}
}
}
+1 -1
View File
@@ -12,7 +12,7 @@ using LeafWeb.Web.Charter;
namespace LeafWeb.Web.Controllers namespace LeafWeb.Web.Controllers
{ {
public class LeafCharterController : Controller public class LeafCharterController : Controller
{ {
public ActionResult Index() public ActionResult Index()
{ {
-4
View File
@@ -10,10 +10,6 @@ namespace LeafWeb.Web.Controllers
{ {
public ActionResult Index() public ActionResult Index()
{ {
var dataService = new DataService();
var fluxnetSites = dataService.GetFluxnetSites().ToList();
// initialize the session storage to retain SessionID between requests // initialize the session storage to retain SessionID between requests
Session["placeholder"] = 0; Session["placeholder"] = 0;
return View(); return View();