using System.Web.Mvc;
using TwitterPractice.Models;


namespace TwitterPractice.Controllers
{
    public class HomeController : Controller
    {
        private static string title = "Twitter Practice!";
        private TwitterModels _twitterModels;

        public HomeController()
            : base()
        {
            _twitterModels = new TwitterModels();
        }

        public ActionResult Index()
        {
            ViewBag.HasQsVars = (Request.QueryString.Keys.Count > 0);
            ViewBag.QueryString = Request.QueryString;
            ViewBag.Message = title;
            
            return View();
        }

        public ActionResult UserTimelineFragment()
        {
            string username = Request.QueryString["username"];
            if (null == username)
            {
                return new HttpNotFoundResult("you must provide a username, derp.");
            }
            else
            {
                try
                {
                    ViewBag.UserTimeline = _twitterModels.GetTwitterStream(username);
                    ViewBag.Username = username;
                    return View();
                }
                catch (System.SystemException e)
                {
                    return new HttpNotFoundResult("FAIL: " + e.Message);
                }
            }
        }
    }
}
