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

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