Pergunta

I'm using EWS Managed API 2.0. I'm using the Calendaring part where you can book appointments as follows :

Appointment appointment = new Appointment(service);

//Set properties on the appointment.
appointment.Subject = "Dentist Appointment";
appointment.Body = "The appointment is with Dr. Smith.";
appointment.Start = new DateTime(2009, 3, 1, 9, 0, 0);
appointment.End = appointment.Start.AddHours(2);

//Save the appointment.
appointment.Save(SendInvitationsMode.SendToNone);

How can I using the API check the status of the booking and whether it was booked or not due to a conflict in the date (Success/Error/Conflict)? right now I'm able to check this through the outlook, but I'd like to know this information from the API. I've looked into the API documentation but I couldn't find anything.

Appreciate your help/guidance.

Foi útil?

Solução

You should first check the availability of all attendees before saving your appointment. AvailabilityData will return you Result (ServiceResult.Success, ServiceResult.Warning, or ServiceResult.Error) and further you can check ErrorMessage property to find proper return message for each conflicting availability. If availability is not conflicting for any of the attendees, you can save your Appointment object.

AvailabilityOptions availabilityOptions = new AvailabilityOptions();
availabilityOptions.MeetingDuration = 60;
availabilityOptions.MaximumNonWorkHoursSuggestionsPerDay = 4;
availabilityOptions.MinimumSuggestionQuality = SuggestionQuality.Good;
availabilityOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;

List<AttendeeInfo> attendees = new List<AttendeeInfo>();
attendees.Add(
    new AttendeeInfo()
    {
        SmtpAddress = "org@acme.com",
        AttendeeType = MeetingAttendeeType.Organizer
    });

attendees.Add(
    new AttendeeInfo()
    {
        SmtpAddress = "at1@acme.com",
        AttendeeType = MeetingAttendeeType.Required
    });

attendees.Add(
    new AttendeeInfo()
    {
        SmtpAddress = "room1@acme.com",
        AttendeeType = MeetingAttendeeType.Room
    });

GetUserAvailabilityResults availabilityResults =
        service.GetUserAvailability(
            attendees,
            new TimeWindow(DateTime.Now, DateTime.Now.AddDays(1)),
            AvailabilityData.FreeBusyAndSuggestions,
            availabilityOptions
        );

// Here check the availability Result and ErrorMessage of each attendees
// availabilityResults.AttendeesAvailability[0].Result
// availabilityResults.AttendeesAvailability[0].ErrorMessage
// ServiceResult.Success
// ServiceResult.Warning
// ServiceResult.Error
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top