adding a model and a form and other stuff to make it right in a smallish way
This commit is contained in:
parent
168b2d24eb
commit
29141a90fb
@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Net;
|
||||
using System.Web.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Web.Mvc;
|
||||
using TwitterPractice.Models;
|
||||
|
||||
|
||||
namespace TwitterPractice.Controllers
|
||||
@ -10,12 +7,13 @@ namespace TwitterPractice.Controllers
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private static string title = "Twitter Practice!";
|
||||
private static string requestTemplate;
|
||||
private string requestTemplate;
|
||||
private TwitterModels _twitterModels;
|
||||
|
||||
public HomeController()
|
||||
: base()
|
||||
{
|
||||
requestTemplate = ConfigurationManager.AppSettings["TwitterRequestTemplate"];
|
||||
_twitterModels = new TwitterModels();
|
||||
}
|
||||
|
||||
public ActionResult Index()
|
||||
@ -26,18 +24,17 @@ namespace TwitterPractice.Controllers
|
||||
string username = Request.QueryString["username"];
|
||||
if (null == username)
|
||||
{
|
||||
username = "meatballhat";
|
||||
ViewBag.UserTimeline = null;
|
||||
ViewBag.Username = null;
|
||||
}
|
||||
ViewBag.UserTimeline = GetTwitterStream(username);
|
||||
ViewBag.Username = username;
|
||||
else
|
||||
{
|
||||
ViewBag.UserTimeline = _twitterModels.GetTwitterStream(username);
|
||||
ViewBag.Username = username;
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
private JArray GetTwitterStream(string username="meatballhat")
|
||||
{
|
||||
string requestUrl = String.Format(requestTemplate, username);
|
||||
WebClient req = new WebClient();
|
||||
return JArray.Parse(req.DownloadString(requestUrl));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
23
TwitterPractice/TwitterPractice/Models/TwitterModels.cs
Normal file
23
TwitterPractice/TwitterPractice/Models/TwitterModels.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Net;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace TwitterPractice.Models
|
||||
{
|
||||
public class TwitterModels
|
||||
{
|
||||
private string requestTemplate;
|
||||
public TwitterModels()
|
||||
{
|
||||
requestTemplate = ConfigurationManager.AppSettings["TwitterRequestTemplate"];
|
||||
}
|
||||
|
||||
public JArray GetTwitterStream(string username = "meatballhat")
|
||||
{
|
||||
string requestUrl = String.Format(requestTemplate, username);
|
||||
WebClient req = new WebClient();
|
||||
return JArray.Parse(req.DownloadString(requestUrl));
|
||||
}
|
||||
}
|
||||
}
|
@ -71,6 +71,7 @@
|
||||
<DependentUpon>Global.asax</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Models\AccountModels.cs" />
|
||||
<Compile Include="Models\TwitterModels.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -1,6 +1,12 @@
|
||||
@using Newtonsoft.Json.Linq;
|
||||
@{ViewBag.Title = "Home Page";}
|
||||
|
||||
<form action="" method="get">
|
||||
<label for="username-input">username:</label>
|
||||
<input type="text" id="username-input" name="username" />
|
||||
<input type="submit" name="submit" value="Submit" />
|
||||
</form>
|
||||
|
||||
<h2>@ViewBag.Message</h2>
|
||||
@if (ViewBag.HasQsVars)
|
||||
{
|
||||
@ -12,10 +18,13 @@
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
|
||||
|
||||
@if (null != ViewBag.Username)
|
||||
{
|
||||
<div id="user-timeline">
|
||||
<h4>user timeline for @ViewBag.Username</h4>
|
||||
|
||||
|
||||
<ul id="timeline-entries">
|
||||
@foreach (JObject entry in ViewBag.UserTimeline)
|
||||
{
|
||||
@ -24,6 +33,5 @@
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
|
||||
<!-- @ViewBag.UserTimeline -->
|
||||
</div>
|
||||
</div>
|
||||
}
|
Loading…
Reference in New Issue
Block a user