public JsonResult FetchEvents(double start, double end)
{
var username = Session["Username"] as string;
if(string.IsNullOrWhiteSpace(username))
{
return null; // Return nothing if username is empty
}
var fromDate = ConvertFromUnixTimestamp(start);
var toDate = ConvertFromUnixTimestamp(end);
var repository = Resolver.Resolve<IEventRepository>();
var eventsList = repository.GetEventsForUser(username, fromDate, toDate);
var eventObjects = from evt in eventsList
select new {
id = evt.Id,
title = evt.Title,
start = evt.FromDate.ToString("s"),
end = evt.ToDate.ToString("s"),
allDay = false
};
var rowsArray = eventObjects.ToArray();
return Json(rowsArray, JsonRequestBehavior.AllowGet);
}
I came across this code snippet on a blog post here and I am trying to understand its functionality. My goal is to utilize fullcalendar to fetch events from the database and enable users to add events using C# and Razor. Although this code generates a JSON object dynamically, I need guidance on adapting it to work with SQL and C#. Any assistance or suggestions would be greatly appreciated.