public async Task PersistCalendarEvents(ExecutionContext context) { var events = await _googleCalendarService.GetEvents(context); var savedEvents = _eventRepository.LoadAll(); try { if (events.Items is { Count : > 0 }) { foreach (var item in events.Items) { var googleEvent = new GoogleEvent(item); if (!googleEvent.HappenedToday()) { continue; } var @event = savedEvents.FirstOrDefault(e => e.Id == item.Id); if (@event == null) { await _eventRepository.Upsert(new Event(googleEvent)); } else if ([email protected](googleEvent.StartDate)) { @event.UpdateEvent(googleEvent); await _eventRepository.Upsert(@event); } } } }
public async Task <IActionResult> EnsureUser([FromBody] EnsureParams parameters) { var user = await service.Ensure(parameters.Email, parameters.Name); var events = await calendarService.GetEvents(parameters.AccessToken); await eventService.SaveEventsForEmployee(events.Items?.ToEvents(user.EmployeeID)); return(Ok(new CallbackResult { Role = user.Role, Id = user.EmployeeID, })); }
public async Task <ActionResult> SendNotification() { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var moodTracker = await _databaseService.GetMoodTrackerAsync(userId); Events events = _calendarService.GetEvents(); if (events != null) { string reminder = "Today's Events:\n"; foreach (var eventItem in events.Items) { if (eventItem.Description == "Activity") { reminder += string.Format($"You have {eventItem.Summary} at {eventItem.Start.DateTime} \n"); } } await _smsService.SendSMS(moodTracker.PhoneNumber, reminder); } return(RedirectToAction(nameof(Index))); }
public async Task MakeEvents(IReadOnlyList <ScheduleDiff> schedule, WeekSchedule updatedWeekSchedule) { Calendar calendar = await _calendarService.GetCalendarById(_googleCalendarId); if (calendar == null) { throw new CalendarNotFoundException(_googleCalendarId); } var timezone = calendar.TimeZone; EventsResource.ListRequest request = _calendarService.CreateListRequestForWeek( _googleCalendarId, updatedWeekSchedule.Year, updatedWeekSchedule.WeekNumber); Events result = await _calendarService.GetEvents(request); var allRows = new List <Event>(); while (result.Items != null) { // Add the rows to the final list allRows.AddRange(result.Items); // We will know we are on the last page when the next page token is null. // If this is the case, break. if (result.NextPageToken == null) { break; } // Prepare the next page of results request.PageToken = result.NextPageToken; // Execute and process the next page request result = await _calendarService.GetEvents(request); } foreach (Event ev in allRows) { _ = await _calendarService.DeleteEvent(_googleCalendarId, ev); } // add items to calendar. IOrderedEnumerable <ScheduleDiff> addedSchedules = schedule .Where(x => x.Status is ScheduleStatus.Added or ScheduleStatus.Unchanged) .OrderBy(x => x.Start) .ThenBy(x => x.Status); foreach (ScheduleDiff item in addedSchedules) { var extendedProperty = new Event.ExtendedPropertiesData { Shared = new Dictionary <string, string> { { "Week", item.SingleShift.WeekSchedule.Year + "-" + item.SingleShift.WeekSchedule.WeekNumber }, }, }; var newEvent = new Event { Start = CreateEventDateTime(item.SingleShift.StartDateTime, timezone), End = CreateEventDateTime(item.SingleShift.EndDateTime, timezone), Description = string.Empty, Location = item.SingleShift.Location, Summary = item.SingleShift.Location, ExtendedProperties = extendedProperty, }; _ = await _calendarService.InsertEvent(_googleCalendarId, newEvent); } }
public void MakeEvents(IList <ScheduleDiff> schedule) { var weeks = schedule.Select(x => x.Schedule.Week).Distinct(); foreach (var w in weeks) { /* * List<string> xxy = new List<string>(); * //xxy.Add("MadeByApplication=Coen"); * xxy.Add("Week=" + w.Year + "-" + w.WeekNr); * var x = new Google.Apis.Util.Repeatable<string>(xxy); * * * * var request = calendarService.CreateListRequest(calendarId); * request.MaxResults = 100; * request.ShowDeleted = false; * * //request.SharedExtendedProperty = x; * request.SharedExtendedProperty = "Week=" + w.Year + "-"+ w.WeekNr; */ var request = calendarService.CreateListRequestForWeek(googleCalendarId, w); var result = calendarService.GetEvents(request); var allRows = new List <Event>(); while (result.Items != null) { //Add the rows to the final list allRows.AddRange(result.Items); // We will know we are on the last page when the next page token is // null. // If this is the case, break. if (result.NextPageToken == null) { break; } // Prepare the next page of results request.PageToken = result.NextPageToken; // Execute and process the next page request result = calendarService.GetEvents(request); } foreach (Event ev in allRows) { calendarService.DeleteEvent(googleCalendarId, ev); } } // add items to calendar. foreach (var item in schedule.Where(x => x.Status == ScheduleStatus.Added).OrderBy(x => x.Start).ThenBy(x => x.Status)) { var extendedProperty = new Event.ExtendedPropertiesData(); extendedProperty.Shared = new Dictionary <string, string>(); // x.Shared.Add("MadeByApplication", "Coen"); extendedProperty.Shared.Add("Week", item.Schedule.Week.Year + "-" + item.Schedule.Week.WeekNr); // queryEvent.SharedExtendedProperty = "EventID=3684"; var newEvent = new Event { Start = new EventDateTime { DateTime = item.Schedule.StartDateTime }, End = new EventDateTime { DateTime = item.Schedule.EndDateTime }, Description = "Ja, je moet werken! xx coen", Location = item.Schedule.Location, Summary = item.Schedule.Location, ExtendedProperties = extendedProperty }; var e = calendarService.InsertEvent(googleCalendarId, newEvent); } // [email protected] -> Gmail Account (default Kalender) // var request = service.Events.Create("*****@*****.**", newEvent); }