Last active
September 29, 2017 13:28
-
-
Save rbaty-barr/ac6640476be4e888eebc81fd915077f0 to your computer and use it in GitHub Desktop.
A class of helpers i am using for an intranet project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getDateInfo(info) { | |
var test = info.toString(); | |
$.ajax({ | |
type: 'POST', | |
url: "/umbraco/surface/rendercalendar/listevents", | |
//contentType: "application/json; charset=utf-8", | |
data: {'matchThis': test}, | |
datatype: "json", | |
success: function (data) { | |
console.log(data); | |
$("#calDetails").html("<p>" + data[0]['summary'] + "<br/>Duration: " + data[0]['duration'] + "</p>"); | |
} | |
}); | |
} | |
$(document).ready(function () { | |
$.ajax({ | |
type: 'GET', | |
url: "/umbraco/surface/rendercalendar/getdates", | |
datatype: "json", | |
success: function (data) { | |
$('.calendar').pignoseCalendar({ | |
scheduleOptions: { | |
colors: { | |
allday: '#ff0000', | |
regular: '#5c6270', | |
meetup: '#ef8080', | |
} | |
}, | |
schedules: data, | |
select: function (date) { | |
getDateInfo(date[0]); | |
} | |
}); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Ical.Net; | |
using System; | |
using System.IO; | |
using System.Net.Http; | |
using System.Collections.Generic; | |
using System.Web.Mvc; | |
using Umbraco.Web.Mvc; | |
using System.Linq; | |
using Newtonsoft.Json; | |
using Ical.Net.DataTypes; | |
using System.Globalization; | |
namespace csacIntranetPrototype.App_Code | |
{ | |
class CalDate | |
{ | |
public string name; | |
public string date; | |
} | |
class DayEvent | |
{ | |
public string description; | |
public string summary; | |
public string start; | |
public string duration; | |
} | |
public class Helpers | |
{ | |
public static CalendarCollection LoadFromUriAsync(Uri uri) | |
{ | |
using (var client = new HttpClient()) | |
{ | |
using (var response = client.GetAsync(uri).Result) | |
{ | |
response.EnsureSuccessStatusCode(); | |
var result = response.Content.ReadAsStringAsync().Result; | |
var calendarCollection = Ical.Net.Calendar.LoadFromStream(new StringReader(result)) as CalendarCollection; | |
return calendarCollection; | |
} | |
} | |
} | |
} | |
public class RenderCalendarController : SurfaceController | |
{ | |
public ActionResult GetDates() | |
{ | |
CalendarCollection calendarCollection = Helpers.LoadFromUriAsync(new Uri("https://calendar.google.com/calendar/ical/bps101.net_6s20210upb019c4kd3t9an1t08%40group.calendar.google.com/public/basic.ics")); | |
var firstCalendar = calendarCollection.First(); | |
List<CalDate> theDates = new List<CalDate>(); | |
foreach (var item in firstCalendar.Events) | |
{ | |
DateTime startDate = item.Start.AsSystemLocal; | |
var duration = item.Duration; | |
var theCategory = item.IsAllDay ? "allday" : "regular"; | |
theDates.Add(new CalDate() { name = theCategory, date = startDate.ToString("yyyy-MM-dd") }); | |
} | |
return Json(theDates, JsonRequestBehavior.AllowGet); | |
} | |
public ActionResult ListEvents(string matchThis) | |
{ | |
string dFormat = "ddd MMM dd yyyy HH:mm:ss 'GMT'K"; | |
DateTime checkDate = DateTime.ParseExact(matchThis, dFormat, null); | |
CalendarCollection calendarCollection = Helpers.LoadFromUriAsync(new Uri("https://calendar.google.com/calendar/ical/bps101.net_6s20210upb019c4kd3t9an1t08%40group.calendar.google.com/public/basic.ics")); | |
var firstCalendar = calendarCollection.First(); | |
var testDate = new DateTime(2017, 9, 4); | |
var theEventList = firstCalendar.Events.Where(x => x.Start.AsSystemLocal.ToString("MMMM dd, yyyy") == checkDate.ToString("MMMM dd, yyyy")); | |
List <DayEvent> theEvents = new List<DayEvent>(); | |
if(theEventList.Any()){ | |
foreach( var item in theEventList) | |
{ | |
DateTime startDate = item.Start.AsSystemLocal; | |
var description = item.Description; | |
var summary = item.Summary; | |
var duration = item.Duration; | |
theEvents.Add(new DayEvent { description = description, start = startDate.ToString("MMMM dd, yyyy"), summary = summary, duration = duration.ToString("hh':'mm") }); //startDate.ToString("MMMM dd, yyyy") | |
} | |
} | |
return Json(theEvents, JsonRequestBehavior.AllowGet); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment