public async Task<ActionResult> Create()
        {
            string token = (string)Session["access_token"];
            string email = (string)Session["user_email"];
            if (string.IsNullOrEmpty(token))
            {
                // If there's no token in the session, redirect to Home
                return Redirect("/");
            }

            try
            {
                OutlookServicesClient client = new OutlookServicesClient(new Uri("https://outlook.office.com/api/v2.0"),
                    async () =>
                    {
                        // Since we have it locally from the Session, just return it here.
                        return token;
                    });

              
                Location location = new Location
                {
                    DisplayName = "Water cooler"
                };

                // Create a description for the event    
                ItemBody body = new ItemBody
                {
                    Content = "Status updates, blocking issues, and next steps",
                    ContentType = BodyType.Text
                };

                // Create the event object
                DateTimeTimeZone start=new DateTimeTimeZone() ;
                string dateTimeFormat = "yyyy-MM-ddThh:mm:ss";
                string timeZone = "Pacific Standard Time";//"Eastern Standard Time";

                start.DateTime = new DateTime(2016, 1, 22, 14, 30, 0).ToString(dateTimeFormat);
                start.TimeZone = timeZone;

                DateTimeTimeZone end = new DateTimeTimeZone();
                end.DateTime = new DateTime(2016, 1, 22, 15, 30, 0).ToString(dateTimeFormat);
                end.TimeZone = timeZone;

                Event newEvent = new Event
                {
                    Subject = "Sync up",
                    Location = location,
                    Start = start,
                    End = end,
                    Body = body
                };

                newEvent.Recurrence = new PatternedRecurrence();
                newEvent.Recurrence.Range = new RecurrenceRange();

                string dateFormat = "yyyy-MM-dd";
                newEvent.Recurrence.Range.EndDate = DateTime.Now.AddYears(1).ToString(dateFormat);
                newEvent.Recurrence.Range.StartDate = DateTime.Now.ToString(dateFormat);
                newEvent.Recurrence.Range.NumberOfOccurrences = 11;

                newEvent.Recurrence.Pattern = new RecurrencePattern();
                newEvent.Recurrence.Pattern.Type = RecurrencePatternType.Weekly;
                newEvent.Recurrence.Pattern.Interval = 1;
                newEvent.Recurrence.Pattern.DaysOfWeek= new List<Microsoft.Office365.OutlookServices.DayOfWeek>() { Microsoft.Office365.OutlookServices.DayOfWeek.Friday };
                // Add the event to the default calendar
                await client.Me.Events.AddEventAsync(newEvent);


                //client.Me.Calendars.AddCalendarAsync()
                //client.Me.Calendars.AddCalendarAsync(new ICalendar)
                var eventResults = await client.Me.Events
                                    .OrderByDescending(e => e.Start.DateTime)
                                    .Take(10)
                                    .Select(e => new Models.DisplayEvent(e.Subject, e.Start.DateTime, e.End.DateTime))
                                    .ExecuteAsync();

                return View("Calendar",eventResults.CurrentPage);
            }
            catch (AdalException ex)
            {
                return Content(string.Format("ERROR retrieving events: {0}", ex.Message));
            }

        }
Beispiel #2
0
        /// <summary>
        /// Schedules meeting
        /// </summary>
        /// <param name="accessToken">Access Token for API</param>
        /// <param name="meeting">Meeting object containing all required data for scheduling meeting</param>
        /// <returns>Task of <see cref="Event"/></returns>
        public async Task <Office.Event> ScheduleMeeting(string accessToken, Office.Event meeting)
        {
            try
            {
                Office.Recipient    organizer      = new Office.Recipient();
                Office.EmailAddress organizerEmail = new Office.EmailAddress();

                organizerEmail.Address = "*****@*****.**"; // organizer email address
                organizerEmail.Name    = "Display Name";                  // organizer display name

                organizer.EmailAddress = organizerEmail;

                meeting.IsOrganizer = false;
                meeting.Organizer   = organizer;

                Office.OutlookServicesClient sc = new Office.OutlookServicesClient(new Uri("https://outlook.office.com/api/v2.0/me/events"), () => GetAccessToken("office"));

                await sc.Me.Events.AddEventAsync(meeting);

                //var httpResponseMessage = await _httpService.AuthenticatedPost(ScheduleMeetingEndpoint, accessToken, meeting, "UTC");
                //var scheduledMeeting = JsonConvert.DeserializeObject<Office.Event>(await httpResponseMessage.Content.ReadAsStringAsync());

                return(null);// scheduledMeeting;
            }
            catch (Exception ex)
            {
                _loggingService.Error(ex);
                throw;
            }
        }
        public static async Task Create(Event newEvent)
        {
            var client = await O365Util.GetOutlookClient(Capabilities.Calendar);

            await client.Me.Events.AddEventAsync(newEvent);
        }
    public async Task AddEvent(MyEvent myEvent) {
      var client = await EnsureClientCreated();

      Location myEventLocation = new Location();
      myEventLocation.DisplayName = myEvent.Location;

      var newEvent = new Event {
        Subject = myEvent.Subject,
        Start = myEvent.Start,
        End = myEvent.End,
        Location = myEventLocation
      };
      await client.Me.Events.AddEventAsync(newEvent);
    }
Beispiel #5
0
        public async Task GetInstances()
        {
            var @event = new Event
            {
                Subject = "subject",
                Body = new ItemBody
                {
                    Content = "bodyContent"
                },
                Recurrence = new PatternedRecurrence
                {
                    Pattern =
                        new RecurrencePattern
                        {
                            Type = RecurrencePatternType.Weekly,
                            Interval = 1,
                            Month = 0,
                            Index = WeekIndex.First,
                            FirstDayOfWeek = DayOfWeek.Sunday,
                            DayOfMonth = 0,
                            DaysOfWeek = new[] {DayOfWeek.Tuesday}
                        },
                    Range = new RecurrenceRange { Type = RecurrenceRangeType.NoEnd, StartDate = DateTimeOffset.Now, EndDate = DateTimeOffset.MinValue, NumberOfOccurrences = 0 }
                },
                Attendees =
                    new[]
                    {
                        new Attendee
                        {
                            EmailAddress = new EmailAddress {Address = "*****@*****.**", Name = "piotrp"},
                            Type = AttendeeType.Required
                        }
                    },
            };
            
            await client.Me.Events.AddEventAsync(@event);

            var instances = await client.Me.Calendar.Events.GetById(@event.Id).GetInstances(DateTimeOffset.Now, DateTimeOffset.Now).ExecuteAsync();
        }
Beispiel #6
0
        public void CreateConvertDeleteEvent()
        {
            var newEvent = new Event()
            {
                Start = new DateTimeOffset(2015, 4, 8, 17, 0, 0, new TimeSpan(0, 4, 0, 0)),
                End = new DateTimeOffset(2015, 4, 8, 18, 0, 0, new TimeSpan(0, 4, 0, 0))
            };

            client.Me.Events.AddEventAsync(newEvent).Wait();

            newEvent.Start = new DateTimeOffset(2015, 4, 8, 0, 0, 0, new TimeSpan(0, -4, 0, 0));
            newEvent.End =   new DateTimeOffset(2015, 4, 8, 0, 0, 0, new TimeSpan(0, -4, 0, 0));

            newEvent.StartTimeZone = "Eastern Standard Time";
            newEvent.EndTimeZone = "Eastern Standard Time";

            newEvent.IsAllDay = true;
            newEvent.UpdateAsync().Wait();

            newEvent.DeleteAsync().Wait();
        }
        /// <summary>
        /// Adds a new event to user's default calendar
        /// </summary>
        /// <param name="LocationName">string. The name of the event location</param>
        /// <param name="BodyContent">string. The body of the event.</param>
        /// <param name="Attendees">string. semi-colon delimited list of invitee email addresses</param>
        /// <param name="EventName">string. The subject of the event</param>
        /// <param name="start">DateTimeOffset. The start date of the event</param>
        /// <param name="end">DateTimeOffset. The end date of the event</param>
        /// <param name="startTime">TimeSpan. The start hour:Min:Sec of the event</param>
        /// <param name="endTime">TimeSpan. The end hour:Min:Sec of the event</param>
        /// <returns>The Id of the event that was created; Otherwise, null.</returns>
        public static async Task<string> AddCalendarEventWithArgsAsync(
            string LocationName,
            string BodyContent,
            string Attendees,
            string EventName,
            DateTimeOffset start,
            DateTimeOffset end,
            TimeSpan startTime,
            TimeSpan endTime)
        {
            string newEventId = string.Empty;
            Location location = new Location();
            location.DisplayName = LocationName;
            ItemBody body = new ItemBody();
            body.Content = BodyContent;
            body.ContentType = BodyType.Text;
            string[] splitter = { ";" };
            var splitAttendeeString = Attendees.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
            Attendee[] attendees = new Attendee[splitAttendeeString.Length];
            for (int i = 0; i < splitAttendeeString.Length; i++)
            {
                attendees[i] = new Attendee();
                attendees[i].Type = AttendeeType.Required;
                attendees[i].EmailAddress = new EmailAddress() { Address = splitAttendeeString[i] };
            }

            Event newEvent = new Event
            {
                Subject = EventName,
                Location = location,
                Attendees = attendees,
                Start = start,
                End = end,
                Body = body,
            };
            //Add new times to start and end dates.
            newEvent.Start = (DateTimeOffset?)CalcNewTime(newEvent.Start, start, startTime);
            newEvent.End = (DateTimeOffset?)CalcNewTime(newEvent.End, end, endTime);

            // Make sure we have a reference to the calendar client
            var exchangeClient = await GetOutlookClientAsync();

            // This results in a call to the service.
            await exchangeClient.Me.Events.AddEventAsync(newEvent);
            Debug.WriteLine("Added event: " + newEvent.Id);
            return newEvent.Id;

        }
        /// <summary>
        /// Adds a new event to user's default calendar
        /// </summary>
        public static async Task<string> AddCalendarEventAsync()
        {

            // Make sure we have a reference to the Exchange client
            var client = await GetOutlookClientAsync();

            Location location = new Location
            {
                DisplayName = "Water cooler"
            };
            ItemBody body = new ItemBody
            {
                Content = "Status updates, blocking issues, and next steps",
                ContentType = BodyType.Text
            };

            Attendee[] attendees =  
        { 
            new Attendee  
            { 
                Type = AttendeeType.Required, 
                EmailAddress = new EmailAddress  
                { 
                    Address = "*****@*****.**" 
                }, 
            }, 
        };

            Event newEvent = new Event
            {
                Subject = "Weekly Sync",
                Location = location,
                Attendees = attendees,
                Start = new DateTimeOffset(new DateTime(2014, 12, 1, 9, 30, 0)),
                End = new DateTimeOffset(new DateTime(2014, 12, 1, 10, 0, 0)),
                Body = body
            };

            await client.Me.Calendar.Events.AddEventAsync(newEvent);

            // Get the ID of the event. 
            string eventId = newEvent.Id;

            Debug.WriteLine("Added event: " + eventId);
            return eventId;


        }
        public async Task<Event> ScheduleRepair(DashboardInspectionDetailsViewModel model)
        {
            DateTime repairDate = DateTime.Parse(model.timeSlotsSelectedValue);
            ScheduleRepairUpdate updateJson = new ScheduleRepairUpdate();
            updateJson.sl_dispatcherComments = model.dispatcherComments;
            updateJson.sl_repairScheduled = repairDate.ToUniversalTime();
            updateJson.sl_repairPerson = model.repairPeopleSelectedValue;
            updateJson.__metadata = new metadata { type = "SP.Data.IncidentsListItem" };
            await SuiteLevelWebApp.Utils.RestHelper.PostRestDataToDemoSite("/_api/lists/GetByTitle('Incidents')/Items(" + model.incidentId + ")", JsonConvert.SerializeObject(updateJson), _token);

            var incident = await GetIncidentById(model.incidentId);
            var repairPeople = await GetRepairPeopleByEmailAddress(model.repairPeopleSelectedValue);

            //create a new event 
            Attendee attendee = new Attendee
            {
                EmailAddress = new EmailAddress
                {
                    Address = repairPeople.sl_emailaddress,
                    Name = repairPeople.Title
                },
                Type = AttendeeType.Required
            };

            Attendee[] attendees = new Attendee[1];
            attendees[0] = attendee;

            Event newEvent = new Event
            {
                Subject = "Repair Event",
                Body = new ItemBody
                {
                    Content = incident.sl_dispatcherComments,
                    ContentType = BodyType.HTML
                },
                ShowAs = FreeBusyStatus.Busy,
                Start = repairDate.ToUniversalTime(),
                End = (repairDate.AddHours(1)).ToUniversalTime(),
                Location =  new Location
                {
                    DisplayName = incident.sl_roomID.Title
                },
                Attendees = attendees
            };

            return newEvent;
        }
        /// <summary>
        /// Adds a new event to user's default calendar
        /// </summary>
        /// <param name="LocationName">string. The name of the event location</param>
        /// <param name="BodyContent">string. The body of the event.</param>
        /// <param name="Attendees">string. semi-colon delimited list of invitee email addresses</param>
        /// <param name="EventName">string. The subject of the event</param>
        /// <param name="start">DateTimeOffset. The start date of the event</param>
        /// <param name="end">DateTimeOffset. The end date of the event</param>
        /// <param name="startTime">TimeSpan. The start hour:Min:Sec of the event</param>
        /// <param name="endTime">TimeSpan. The end hour:Min:Sec of the event</param>
        /// <returns></returns>
        internal async Task<string> AddCalendarEventAsync(
            string LocationName,
            string BodyContent,
            string Attendees,
            string EventName,
            DateTimeOffset start,
            DateTimeOffset end,
            TimeSpan startTime,
            TimeSpan endTime)
        {
            string newEventId = string.Empty;
            Location location = new Location();
            location.DisplayName = LocationName;
            ItemBody body = new ItemBody();
            body.Content = BodyContent;
            body.ContentType = BodyType.Text;
            string[] splitter = { ";" };
            var splitAttendeeString = Attendees.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
            Attendee[] attendees = new Attendee[splitAttendeeString.Length];
            for (int i = 0; i < splitAttendeeString.Length; i++)
            {
                attendees[i] = new Attendee();
                attendees[i].Type = AttendeeType.Required;
                attendees[i].EmailAddress = new EmailAddress() { Address = splitAttendeeString[i], Name = splitAttendeeString[i] };
            }

            Event newEvent = new Event
            {
                Subject = EventName,
                Location = location,
                Attendees = attendees,
                Start = start,
                End = end,
                Body = body,
            };
            //Add new times to start and end dates.
            newEvent.Start = (DateTimeOffset?)CalcNewTime(newEvent.Start, start, startTime);
            newEvent.End = (DateTimeOffset?)CalcNewTime(newEvent.End, end, endTime);

            try
            {
                // Make sure we have a reference to the calendar client
                var exchangeClient = await AuthenticationHelper.EnsureOutlookClientCreatedAsync();

                // This results in a call to the service.
                await exchangeClient.Me.Events.AddEventAsync(newEvent);
                newEventId = newEvent.Id;
            }
            catch (Exception e)
            {
                throw new Exception("We could not create your calendar event: " + e.Message);
            }
            return newEventId;
        }