public async Task BookCalendarEventAsync(User tutor, User student, GoogleTokens googleTokens, DateTime from, DateTime to, CancellationToken cancellationToken) { var cred = SpitballCalendarCred; var x = new System.Resources.ResourceManager(typeof(CalendarResources)); var eventName = x.GetString("TutorCalendarMessage", CultureInfo.CurrentUICulture) ?? "Tutor Session In Spitball"; eventName = string.Format(eventName, tutor.Name, student.Name); var tutorToken = _jsonSerializer.Deserialize <GoogleTokensValue>(googleTokens.Value); using var service = new CalendarService(new BaseClientService.Initializer() { HttpClientInitializer = cred }); var tutorCalendarEmail = _tokenHandler.ReadJwtToken(tutorToken.Id_token).Payload.SingleOrDefault(w => w.Key == "email"); var attendees = new[] { tutor, student }.Select(s => new EventAttendee() { Email = s.Email }).ToList(); attendees.Add(new EventAttendee() { Email = tutorCalendarEmail.Value.ToString() }); var event2 = service.Events.Insert(new Event() { Attendees = attendees, Summary = eventName, Start = new EventDateTime() { DateTime = @from }, End = new EventDateTime() { DateTime = to } }, PrimaryGoogleCalendarId); event2.SendUpdates = EventsResource.InsertRequest.SendUpdatesEnum.All; await event2.ExecuteAsync(cancellationToken); }
public async Task StoreAsync <T>(string key, T value) { if (string.IsNullOrEmpty(key)) { throw new ArgumentException("Key MUST have a value"); } var serialized = NewtonsoftJsonSerializer.Instance.Serialize(value); var entity = await _googleTokenRepository.GetAsync(key, CancellationToken.None); if (entity == null) { entity = new GoogleTokens(key, serialized); await _googleTokenRepository.AddAsync(entity, CancellationToken.None); } entity.Value = serialized; await _googleTokenRepository.UpdateAsync(entity, CancellationToken.None); await _unitOfWork.CommitAsync(CancellationToken.None); }