Skip to content

Instantly share code, notes, and snippets.

@JordiCorbilla
Created September 8, 2015 22:18
Show Gist options
  • Save JordiCorbilla/383a72afcb5de44759ad to your computer and use it in GitHub Desktop.
Save JordiCorbilla/383a72afcb5de44759ad to your computer and use it in GitHub Desktop.
public class SingleStats
{
public String Date;
public Nullable<int> Value;
}
public ActionResult fetchData(int id)
{
XmlDocument doc = new XmlDocument();
doc.Load("c:\\temp\\flickrRepositoryGlobal.xml");
var data = new List<istat>();
// cycle through each child noed
foreach (XmlNode node in doc.DocumentElement.ChildNodes)
{
IStat s = new Stat();
DateTime p;
DateTime.TryParse(node.Attributes["Date"].Value, out p);
s.date = p;
s.views = Int32.Parse(node.Attributes["Views"].Value);
s.comments = Int32.Parse(node.Attributes["Comments"].Value);
s.likes = Int32.Parse(node.Attributes["Likes"].Value);
data.Add(s);
}
var list = new List<singlestats>();
foreach (var item in data)
{
SingleStats stat = new SingleStats();
stat.Date = item.date.ToString("d-MMM-yyyy");
if (id == 1)
stat.Value = item.views;
else if (id == 2)
stat.Value = item.likes;
else if (id == 3)
stat.Value = item.comments;
list.Add(stat);
}
return Json(new { stats = list }, JsonRequestBehavior.AllowGet);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment