public IHttpActionResult Availability(AvailabilityRequest request)
        {
            List<AttendeeInfo> attendees = new List<AttendeeInfo>();

            foreach (var user in request.Users)
            {
                attendees.Add(new AttendeeInfo()
                {
                    SmtpAddress = user,
                    AttendeeType = MeetingAttendeeType.Required
                });
            }

            // Specify availability options.
            AvailabilityOptions myOptions = new AvailabilityOptions();
            myOptions.MeetingDuration = request.DurationMinutes;
            myOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;

            // Return a set of free/busy times.
            var service = ExchangeServer.Open();

            var startTime = DateTime.Parse(request.Start);
            var endTime = DateTime.Parse(request.End);
            GetUserAvailabilityResults freeBusyResults = service.GetUserAvailability(attendees,
                                                                                 new TimeWindow(startTime, endTime),
                                                                                     AvailabilityData.FreeBusy,
                                                                                     myOptions);

            var response = new AvailabilityResponse
            {
                AvailabilityResult = new List<AvailabilityUser>()
            };


            foreach (AttendeeAvailability availability in freeBusyResults.AttendeesAvailability)
            {
                var user = new AvailabilityUser();
                var avail = new List<TimeBlock>();

                foreach (CalendarEvent calendarItem in availability.CalendarEvents)
                {
                    var block = new TimeBlock
                    {
                        Start = calendarItem.StartTime,
                        End = calendarItem.EndTime,
                        StatusEnum = calendarItem.FreeBusyStatus,
                        Status = calendarItem.FreeBusyStatus.ToString()
                    };

                    avail.Add(block);
                }
                user.Availability = avail;
                response.AvailabilityResult.Add(user);
            }

            return Ok(response);
        }
        public void GetAvailability()
        {
            var controller = new AppointmentsController();

            var start = new DateTime(2016, 1, 15, 13, 0, 0);
            var end = start.AddDays(40);
            var request = new AvailabilityRequest
            {
                DurationMinutes = 60,
                Start = start.ToString(),
                End = end.ToString(),
                Users = new List<string>()
                {
                    "*****@*****.**"
                }
            };

            var result = controller.Availability(request) as OkNegotiatedContentResult<AvailabilityResponse>;

            Assert.IsNotNull(result.Content.AvailabilityResult);
            Assert.IsTrue(result.Content.AvailabilityResult.Count > 0);
        }