using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using NHibernate; using NHibernate.Linq; using Sleis.Models; using Sleis.ViewModels; using Sleis.Infrastructure; using Sleis.Service; using Sleis.Utility; using Sleis.Validation; using Sleis.Validation.Attribute; using System.Text; using Sleis.EpaLookupStratgy; using System.Reflection; namespace Sleis.Controllers { [HandleError] public class LookupController : BaseController { public override void Init() { base.Init(); } //For Brandon to fix! - Caching [HttpGet] public JsonResult GetEmissionCalculationMethods() { //TODO: Might want to cache this. Although right now doesn't seem too critical. List result; using (ISession session = SessionFactoryProvider.SessionFactory.OpenSession()) { result = (from d in session.Query() select (d)).ToList(); } return Json(result, JsonRequestBehavior.AllowGet); } [HttpGet] public JsonResult Get(string type, string query, int year, int size = 10) { ListView domain = new ListView(); if (!String.IsNullOrEmpty(type)) { domain.List = LookupUtility.GetLike(type, query, size, year); if (domain.List == null || domain.List.Count == 0) { IEpaLookup lookup = EpaLookupFactory.GetInstance(type); if (lookup != null) { //lookup.LoadList(); was causing list to get loaded twice. domain.List = LookupUtility.GetLike(type, query, size, year); } else { domain.List = LookupUtility.GetLike(type, query, size, year); } } } return Json(domain, JsonRequestBehavior.AllowGet); } [HttpGet] public JsonResult GetCustomQuery(string type, string query, int? year, int size = 10, int facilityId=0, int reportId=0) { ListView domain = new ListView(); if (!String.IsNullOrEmpty(type) && !String.IsNullOrEmpty(query)) { domain.List = PageService.GetSimpleLookupItemByCustomQuery(type, query, facilityId, reportId); //note query is the search term. type will be the queryName domain.List = domain.List.Take(size).ToList(); // reduce to requested number of results. } return Json(domain, JsonRequestBehavior.AllowGet); } [HttpGet] public JsonResult GetScc(string type, string levelOne, string levelTwo, string levelThree, int year=0) { ListView domain = new ListView(); if (year == 0) year = DateTime.Now.Year; if (!String.IsNullOrEmpty(type)) { domain.List = PageService.GetSimpleLookupItemForScc(type, levelOne, levelTwo, levelThree, year); } /*//check if master inventory and filter out bad years if (year == 0) { domain.List = domain.List.Where(x=> x.Year == 0 || x.Year >= DateTime.Now.Year).ToList(); } */ return Json(domain, JsonRequestBehavior.AllowGet); } [Authorize] public ActionResult Reload() { try { //StringBuilder sb = new StringBuilder(); //sb.Append("Lookup Refreshed:
    "); //foreach (string lookupKey in LookupUtility.Reload()) //{ // sb.AppendFormat("
  • {0}
  • ", lookupKey); //} //sb.Append("
"); TempData[Constants.GlobalMessageKey] = new SimpleMessage("Feature disabled. Edit Web.config to reload context."); } catch (Exception ex) { TempData[Constants.GlobalMessageKey] = new SimpleMessage("Error while refreshing lookups: " + ExceptionUtility.GetDeepExceptionMessageOnly(ex), true); } return RedirectToAction("Home", "Public"); } } }