public static async Task <CheckedRoom> GetRoomAvailability(GraphServiceClient graphClient, CheckedRoom room, HttpContext httpContext, DateTime dateTime) { CheckedRoom roomRecent = new CheckedRoom(24) { Id = room.Id, HasMailBox = room.HasMailBox, Available = true, Name = room.Name, ReservedBy = "", RoomType = room.RoomType, Floor = room.Floor, Type = room.Type, Features = "", Occupied = -1, Nodes = room.Nodes, Capacity = room.Capacity, AudioVideo = room.AudioVideo }; if (roomRecent.HasMailBox) { return(await GetRoomSchedule(graphClient, room, dateTime, roomRecent)); } else { roomRecent.Available = false; roomRecent.ReservedBy = "Contact Hospitality Team"; for (int i = 0; i < roomRecent.DaySchedule.Length - 1; i++) { roomRecent.DaySchedule[i] = null; } return(roomRecent); } }
public static async Task <List <CheckedRoom> > GetRooms(string accessToken, string roomListAddress) { var rooms = new List <CheckedRoom>(); try { var action = $"beta/me/findRooms(RoomList='{roomListAddress}')"; var roomList = await DoGraphRequest <GraphRoomList>(accessToken, action); if (roomList.value.Count > 0) { foreach (var graphroom in roomList.value) { var room = new CheckedRoom(24) { Id = graphroom.Address, Name = graphroom.Name }; rooms.Add(room); } } } catch (Exception e) { var msg = e.Message; } return(rooms); }
private static async Task <CheckedRoom> GetRoomSchedule(GraphServiceClient graphClient, CheckedRoom room, DateTime dateTime, CheckedRoom roomRecent) { try { var beginTime = new DateTimeTimeZone { DateTime = dateTime.Date.ToString("yyyy-MM-ddTHH:mm:ssZ"), TimeZone = "UTC" }; var endTime = new DateTimeTimeZone { DateTime = dateTime.Date.AddDays(0).AddHours(23).ToString("yyyy-MM-ddTHH:mm:ssZ"), TimeZone = "UTC" }; var roomFreeBusy = await graphClient.Users[room.Id].Calendar.GetSchedule(new List <string> { room.Id }, endTime, beginTime).Request().PostAsync(); if (roomFreeBusy.First().ScheduleItems.Count() == 0) { roomRecent.Available = true; } else { var orderedRoomSchedules = roomFreeBusy.First().ScheduleItems.Where(r => r.Status != FreeBusyStatus.Free).OrderBy(r => r.Start.DateTime).ToList(); var cetTime = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time"); var scheduleArray = orderedRoomSchedules.ToArray(); var roomBusy = false; for (var s = 0; s < scheduleArray.Length; s++) { var beginHour = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse(scheduleArray[s].Start.DateTime), cetTime).Hour; var endHour = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse(scheduleArray[s].End.DateTime), cetTime).Hour; var hourSchedule = new HourSchedule { Occupied = true, StartTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse(scheduleArray[s].Start.DateTime), cetTime), EndTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse(scheduleArray[s].End.DateTime), cetTime) }; for (int t = beginHour; t <= endHour; t++) { if (t == endHour) { if (TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse(scheduleArray[s].End.DateTime), cetTime).Minute > 0) { roomRecent.DaySchedule[t] = hourSchedule; } } else { roomRecent.DaySchedule[t] = hourSchedule; } } if (DateTime.Parse(scheduleArray[s].Start.DateTime) <= dateTime.ToUniversalTime() && DateTime.Parse(scheduleArray[s].End.DateTime) > dateTime.ToUniversalTime()) { //Event is now roomBusy = true; roomRecent.Available = false; if (roomRecent.FreeAt < TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse(scheduleArray[s].End.DateTime), cetTime)) { //if the end data of current meeting is after the enddate of a previous meeting roomRecent.FreeAt = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse(scheduleArray[s].End.DateTime), cetTime); } } if (DateTime.Parse(scheduleArray[s].Start.DateTime) <= dateTime.ToUniversalTime() && DateTime.Parse(scheduleArray[s].End.DateTime) < dateTime.ToUniversalTime()) { //Event has happenend if (!roomBusy) { roomRecent.Available = true; } } if (DateTime.Parse(scheduleArray[s].Start.DateTime) >= dateTime.ToUniversalTime() && DateTime.Parse(scheduleArray[s].End.DateTime) > dateTime.ToUniversalTime()) { //Event needs to happen if (dateTime.Date == DateTime.Now.Date) { //today if (roomRecent.Available && roomRecent.FreeUntil == default(DateTime)) { roomRecent.FreeUntil = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse(scheduleArray[s].Start.DateTime), cetTime); } } else { //not today roomRecent.FreeAt = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse(scheduleArray[s].End.DateTime), cetTime); } } } } return(roomRecent); } catch (ServiceException e) { roomRecent.Available = false; roomRecent.ReservedBy = "Contact Hospitality Team"; for (int i = 0; i < roomRecent.DaySchedule.Length - 1; i++) { roomRecent.DaySchedule[i] = null; } return(roomRecent); } }