/// <summary> /// Reserves a conference room based on the supplied reservation details. /// </summary> /// <param name="Reservation">The reservation detaills with which to reserve the room.</param> /// <returns><see cref="bool"/> indicating success or conflict with other meetings already on the conference room's calendar.</returns> public async Task <bool> ReserveConferenceRoom(CalendarReservation Reservation) { // First, determine if the room is free during the specified time period. DateTime start = Reservation.StartDate; DateTime end = Reservation.EndDate; List <CalendarEvent> events = await _graphClient.GetConferenceRoomCalendarEvents(Reservation.RoomName, start, end, 30); CalendarEvent existing = null; existing = events.Where(x => (Reservation.StartDate >= x.Start && Reservation.StartDate < x.End) || (Reservation.EndDate > x.Start && Reservation.EndDate <= x.End)).FirstOrDefault(); if (existing != null) { return(false); } else { return(await _graphClient.ReserveConferenceRoom(Reservation.RoomName, Reservation.Username, Reservation.StartDate, Reservation.EndDate)); } }
public async Task <HttpResponseMessage> Reserve(CalendarReservation Reservation) { bool result; try { result = await _service.ReserveConferenceRoom(Reservation); if (result == true) { return(new HttpResponseMessage(System.Net.HttpStatusCode.Created)); } else { return(new HttpResponseMessage(System.Net.HttpStatusCode.Conflict)); } } catch (Exception) { return(new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError)); } }