public async System.Threading.Tasks.Task EventCreateExtendedProperty()
        {
            try
            {
                var myEvent = new Microsoft.Graph.Event();
                myEvent.Subject = "Lunch with my friend";
                myEvent.Body    = new ItemBody()
                {
                    ContentType = BodyType.Text, Content = "Catch up on old times."
                };
                myEvent.Start = new DateTimeTimeZone()
                {
                    DateTime = "2017-05-29T12:00:00", TimeZone = "Pacific Standard Time"
                };
                myEvent.End = new DateTimeTimeZone()
                {
                    DateTime = "2017-05-29T13:00:00", TimeZone = "Pacific Standard Time"
                };
                myEvent.Location = new Location()
                {
                    DisplayName = "In.gredients"
                };
                myEvent.SingleValueExtendedProperties = new EventSingleValueExtendedPropertiesCollectionPage();


                var myCustomIdentifier = "String {66f5a359-4659-4830-9070-00040ec6ac6e} Name courseId";

                var myCustomExtendedProperty = new SingleValueLegacyExtendedProperty()
                {
                    Id    = myCustomIdentifier,
                    Value = "1234567"
                };

                myEvent.SingleValueExtendedProperties.Add(myCustomExtendedProperty);

                // Create the event with the extended property in the service.
                var mySyncdEvent = await graphClient.Me.Calendar.Events.Request()
                                   .AddAsync(myEvent);

                // Get the event with the extended property.
                var mySyncdEventWithExtendedProperty = await graphClient.Me
                                                       .Calendar
                                                       .Events
                                                       .Request()
                                                       .Expand($"singleValueExtendedProperties($filter=id eq '{myCustomIdentifier}')")
                                                       .GetAsync();

                Assert.IsNotNull(mySyncdEventWithExtendedProperty[0].SingleValueExtendedProperties);

                // Delete the event we just created.
                await graphClient.Me.Events[mySyncdEventWithExtendedProperty[0].Id].Request().DeleteAsync();
            }
            catch (Microsoft.Graph.ServiceException e)
            {
                Assert.Fail("Something happened, check out a trace. Error code: {0}", e.Error.Code);
            }
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventModel"/> class from MS Graph event.
        /// </summary>
        /// <param name="msftEvent">MS Graph event.</param>
        public EventModel(Microsoft.Graph.Event msftEvent)
        {
            source = EventSource.Microsoft;
            if (msftEvent.OnlineMeetingUrl == string.Empty)
            {
                msftEvent.OnlineMeetingUrl = null;
            }

            msftEventData = msftEvent;
        }
    // Testing out MSGraph
    public async void graphTesting()
    {
        // Initialize the GraphServiceClient.
        // GraphServiceClient graphClient = Microsoft_Graph_SDK_ASPNET_Connect.Helpers.SDKHelper.GetAuthenticatedClient();
        var graphClient = AuthenticationHelper.GetAuthenticatedClient();

        var myEvent = new Microsoft.Graph.Event();

        myEvent.Subject = "Test";
        myEvent.Body    = new ItemBody()
        {
            ContentType = BodyType.Text, Content = "This is test."
        };
        myEvent.Start = new DateTimeTimeZone()
        {
            DateTime = "2018-10-3T12:00:00", TimeZone = "Pacific Standard Time"
        };
        myEvent.End = new DateTimeTimeZone()
        {
            DateTime = "2018-10-3T13:00:00", TimeZone = "Pacific Standard Time"
        };
        myEvent.Location = new Location()
        {
            DisplayName = "conf room 1"
        };

        var myEvent2 = new Microsoft.Graph.Event();

        myEvent2.Subject = "Test";
        myEvent2.Body    = new ItemBody()
        {
            ContentType = BodyType.Text, Content = "This is test."
        };
        myEvent2.Start = new DateTimeTimeZone()
        {
            DateTime = "2018-10-4T12:00:00", TimeZone = "Pacific Standard Time"
        };
        myEvent2.End = new DateTimeTimeZone()
        {
            DateTime = "2018-10-4T13:00:00", TimeZone = "Pacific Standard Time"
        };
        myEvent2.Location = new Location()
        {
            DisplayName = "conf room 1"
        };


        // Create the event.
        //var user = graphClient.Users["*****@*****.**"].Calendar.Events.Request();
        await graphClient.Users["*****@*****.**"].Calendar.Events.Request().AddAsync(myEvent);
        await graphClient.Users["*****@*****.**"].Calendar.Events.Request().AddAsync(myEvent2);
        await graphClient.Users["*****@*****.**"].Calendar.Events.Request().AddAsync(myEvent);
        await graphClient.Users["*****@*****.**"].Calendar.Events.Request().AddAsync(myEvent2);
    }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventModel"/> class.
        /// </summary>
        /// <param name="source">the event source.</param>
        public EventModel(EventSource source)
        {
            this.source = source;
            switch (this.source)
            {
            case EventSource.Microsoft:
                msftEventData = new Microsoft.Graph.Event();
                break;

            case EventSource.Google:
                gmailEventData = new Google.Apis.Calendar.v3.Data.Event();
                break;

            default:
                throw new Exception("Event Type not Defined");
            }
        }
Example #5
0
        public static Event ToEvent(this Microsoft.Graph.Event e, ChangeType changeType = ChangeType.None, string meetingRoom = null)
        {
            var ev = new Event
            {
                Id          = e.Id,
                Subject     = e.Subject,
                BodyPreview = e.BodyPreview,
                Start       = DateTime.Parse(e.Start.DateTime, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(),
                End         = DateTime.Parse(e.End.DateTime, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(),
                Organizer   = e.Organizer.EmailAddress.Name,
                TimeZone    = e.OriginalStartTimeZone,
                ChangeType  = changeType,
                MeetingRoom = meetingRoom
            };

            return(ev);
        }
        public async Task <IActionResult> CreateEvent(string eventId)
        {
            try
            {
                if (User.Identity.IsAuthenticated)
                {
                    eventId = eventId ?? "248d8ea0-b518-493d-b9c1-0a9f3e4e94c7"; //Just for testing
                    Microsoft.Graph.Event newEvent = await _todoListService.CreateEventAsync(/*(ClaimsIdentity)User.Identity,*/ eventId);

                    ViewData["Response"] = JsonConvert.SerializeObject(newEvent, Formatting.Indented);

                    TempData["Message"] = newEvent != null ? "Success! Your calendar event was created." : "";
                    return(RedirectToAction("Index", "Home"));
                }
            }
            catch (System.Exception e)
            {
                return(RedirectToAction("Error", "Home", new { message = e.Message }));
            }
            return(RedirectToAction("Index", "Home"));
        }