Pulling calender events from Outlook into a database

183 Views Asked by At

I am creating a ASP.NET web app using FullCalender I've added CRUD functionality in JQuery and now I am trying to add integration with outlook calender to pull the events of a user who logs into their outlook account. I've gone through the REST API Tutorial to set up authentication and display events on a page.

My database Has the name MyDatabaseEntities and contains and Events table which contains the entitys EventID, Subject, Description, Start, End, Themecolor and IsFullDay.

How can I modify the below class so that it inserts the events into my database? This would then allow me to display them on my calender.

public async Task<ActionResult> Calendar()
    {
        string token = await GetAccessToken();
        if (string.IsNullOrEmpty(token))
        {
            // If there's no token in the session, redirect to Home
            return Redirect("/");
        }

        string userEmail = await GetUserEmail();

        GraphServiceClient client = new GraphServiceClient(
            new DelegateAuthenticationProvider(
                (requestMessage) =>
                {
                    requestMessage.Headers.Authorization =
                        new AuthenticationHeaderValue("Bearer", token);

                    requestMessage.Headers.Add("X-AnchorMailbox", userEmail);

                    return Task.FromResult(0);
                }));

        try
        {
            var eventResults = await client.Me.Events.Request()
                                .OrderBy("start/dateTime DESC")
                                .Select("subject,start,end")
                                .Top(10)
                                .GetAsync();

            return View(eventResults.CurrentPage);
        }
        catch (ServiceException ex)
        {
            return RedirectToAction("Error", "Home", new { message = "ERROR retrieving events", debug = ex.Message });
        }
    }
0

There are 0 best solutions below