public ActionResult Flair([DefaultValue("html")]string format)
{
string SourceIP = string.IsNullOrEmpty(Request.ServerVariables["HTTP_X_FORWARDED_FOR"]) ?
Request.ServerVariables["REMOTE_ADDR"] :
Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
var location = GeolocationService.HostIpToPlaceName(SourceIP);
var dinners = dinnerRepository.
FindByLocation(location.Position.Lat, location.Position.Long).
OrderByDescending(p => p.EventDate).Take(3);
// Select the view we'll return. Using a switch because we'll add in JSON and other formats later.
// Will probably extract or refactor this.
string view;
switch (format.ToLower())
{
case "javascript":
view = "JavascriptFlair";
break;
default:
view = "Flair";
break;
}
return View(
view,
new FlairViewModel
{
Dinners = dinners.ToList(),
LocationName = string.IsNullOrEmpty(location.City) ? "you" : String.Format("{0}, {1}", location.City, location.RegionName)
}
);
}