using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;

namespace FacebookClient.Controllers
{
    public class Users
    {
        public User[] data;
    }

    public class User
    {
        [JsonProperty("uid")]
        public string UserId { get; set; }
        [JsonProperty("first_name")]
        public string FirstName { get; set; }
        [JsonProperty("last_name")]
        public string LastName { get; set; }
    }

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var formatter = new System.Net.Http.Formatting.JsonMediaTypeFormatter();
            formatter.SupportedMediaTypes.Add(new System.Net.Http.Headers.MediaTypeHeaderValue("text/javascript"));

            Users model = null;
            var client = new HttpClient();
            var task = client.GetAsync("http://graph.facebook.com/fql?q=SELECT+uid,email,first_name,last_name+FROM+user+WHERE+username='pawel.rajba'").ContinueWith(t =>
            {
                var response = t.Result;
                //response.Content.Headers.Remove("Content-Type");response.Content.Headers.Add("Content-Type", "application/json");
                var readTask = response.Content.ReadAsAsync<Users>(new[] { formatter });
                readTask.Wait();
                model = readTask.Result;
            });
            task.Wait();

            return View(model.data);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}
