microsoft graph update a room resource from Tentatively Accepted to Accepted in C#

40 Views Asked by At

in microsoft outlook I have room resources with room delegates. A user reserves a room and an email is sent via outlook for the room delegate to approve the room.

However the users would like to do this outside of the emails. I am attempting to do this in microsoft graph see below.

public static async Task ChangeRoomStatus(string id, string roomEmail, string status)
    {
        var existingEvent = await _appClient.Users[roomEmail].Events[id]
            .Request()
            .Select(e => new { e.Attendees })
            .GetAsync();

        var attendeeToUpdate = existingEvent.Attendees.FirstOrDefault(a => a.EmailAddress.Address == roomEmail);

        if (attendeeToUpdate != null)
        {
            // Update the attendee's status
            attendeeToUpdate.Status.Response = status == "Approved" ? ResponseType.Accepted : ResponseType.Declined;
            attendeeToUpdate.Status.Time = DateTimeOffset.Now;

            // Update only the Attendees property of the existing event
            await _appClient.Users[roomEmail].Events[id]
                .Request()
                .Header("Prefer", "outlook.allow-unsafe-updates=true")
                .UpdateAsync(existingEvent);
        }
        else
        {
            // Handle the case where the attendee is not found
            throw new Exception("Attendee not found");
        }
    }

the email is the email of the room resource and I'm trying to change the status of the attendee that is the room resource to Accepted so that the room will be approved. everything runs through the function and no errors are thrown and in debugger I see the status as "Approved". unfortunately it does not actually update the event. when I look at the event after this successfully runs the status for that attendee is back to tentatively accepted. What gives?

0

There are 0 best solutions below