using System.Linq;
using System.Web.Mvc;

namespace LeafWeb.Web.Controllers
{
	public class FluxnetSiteController : ControllerBase
	{
		public JsonResult Autocomplete(string query)
		{
			var sites = DataService.GetFluxnetSitesAutocomplete(query).Take(50).ToList();
			var data = new
			{
				suggestions =
					from s in sites
					select new
					{
						value = $"{s.SiteName} / {s.FluxnetId}",
						data = s.FluxnetId
					}
			};
			return Json(data, JsonRequestBehavior.AllowGet);
		}
	}
}