public JsonResult GetEvents(double start, double end)
{
var userName = Session["UserName"] as string;
if(string.IsNullOrEmpty(userName))
{
return null;
}
var fromDate = ConvertFromUnixTimestamp(start);
var toDate = ConvertFromUnixTimestamp(end);
var rep = Resolver.Resolve<IEventRepository>();
var events = rep.ListEventsForUser(userName,fromDate,toDate);
var eventList = from e in events
select new {
id = e.Id,
title = e.Title,
start = e.FromDate.ToString("s"),
end = e.ToDate.ToString("s"),
allDay = false
};
var rows = eventList.ToArray();
return Json(rows,JsonRequestBehavior.AllowGet);
}
I have gotten this code from this blog and am trying to make sense of it. What I would like to do is use the fullcalendar code to retrieve events from a database and allow users to add them to a database using C# and Razor. I think this code is close to what I would like in that it is creating the JSON object on the fly, but I need to adapt it to use SQL and C#. Can anyone help with this please?
It’s grabbing an instantiation of
IEventRepositoryfrom the kernel/resolver of a dependency injection framework. Elsewhere in the code/configuration, there will be instructions for the resolver regarding what kind of object should be instantiated when asked for an object of typeIEventRepository. Without seeing that code, it’s anyone’s guess as to what is being handed back from that call, other than it satisfies the interfaceIEventRepository. Likely, there’s only one or two classes that implementIEventRepository. Find them!If you want to read up on DI, I like the ninject docs, but this particular code doesn’t look like ninject.