public async Task <bool> Handle(CreateAppointmentCommand request, CancellationToken cancellationToken) { var result = false; var apponintment = new Models.Dto.Apponintment { Categoria = request.Categoria, ClassEvent = request.ClassEvent, Description = request.Description, Title = request.Title, From = request.From, To = request.To, StartDate = request.StartDate }; var res = await _calendatRepository.CreateAppointment(apponintment); if (res != null) { var GoogleEventModel = new GoogleEventModel() { EventId = res.SpecifiedID.GoogleId, Description = res.Description, Start = res.StartDate, End = res.StartDate.AddMinutes(15), Summary = res.Title, }; result = await _googleCalendarRepository.InsertEvent(GoogleEventModel, "primary") != null; } return(result); }
public async Task <GoogleEventModel> UpdateEvent(GoogleEventModel eventModel, string calendarID) { if (!eventModel.Start.HasValue) { return(null); } var start = eventModel.Start.Value; var service = GetCalendarService(); var calendartimeZone = GetCurrentCalendar(service).TimeZone; var simpleStartDate = new DateTime(start.Year, start.Month, start.Day, start.Hour, start.Minute, start.Second); Event gEvent = new Event { Id = eventModel.EventId, Summary = eventModel.Summary, Location = eventModel.Location, Description = eventModel.Description, Start = new EventDateTime() { DateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(simpleStartDate, TZConvert.IanaToWindows(calendartimeZone)), }, End = new EventDateTime() { DateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(simpleStartDate.AddMinutes(15), TZConvert.IanaToWindows(calendartimeZone)), } }; //gEvent.Start.DateTimeRaw = gEvent.Start.DateTime.Value.ToLongDateString(); //gEvent.End.DateTimeRaw = gEvent.End.DateTime.Value.ToLongDateString(); EventsResource.UpdateRequest request = service.Events.Update(gEvent, calendarID, gEvent.Id); Event UpdatedEvent = await request.ExecuteAsync(); return(UpdatedEvent.MapToGoogleEventModel()); }
public async Task <GoogleEventModel> InsertEvent(GoogleEventModel eventModel, string calendarID) { if (!eventModel.Start.HasValue) { return(null); } var start = eventModel.Start.Value; var service = GetCalendarService(); var simpleStartDate = new DateTime(start.Year, start.Month, start.Day, start.Hour, start.Minute, start.Second); var calendartimeZone = GetCurrentCalendar(service).TimeZone; Event newEvent = new Event() { Id = eventModel.EventId, Summary = eventModel.Summary, Location = eventModel.Location, Description = eventModel.Description, Start = new EventDateTime() { DateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(simpleStartDate, TZConvert.IanaToWindows(calendartimeZone)), TimeZone = calendartimeZone, }, End = new EventDateTime() { DateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(simpleStartDate.AddMinutes(15), TZConvert.IanaToWindows(calendartimeZone)), TimeZone = calendartimeZone, }, Attendees = new EventAttendee[] { new EventAttendee() { Email = _user.Email } }, }; //newEvent.Start.DateTimeRaw = newEvent.Start.DateTime.Value.ToLongDateString(); //newEvent.End.DateTimeRaw = newEvent.End.DateTime.Value.ToLongDateString(); EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarID); Event createdEvent = await request.ExecuteAsync(); return(createdEvent.MapToGoogleEventModel()); }
public static Event MapToEventModel(this GoogleEventModel gEvent) { EventDateTime start = new EventDateTime() { DateTime = gEvent.Start, TimeZone = gEvent.TimeZone }; EventDateTime end = new EventDateTime() { DateTime = gEvent.End, TimeZone = gEvent.TimeZone }; return(new Event() { Description = gEvent.Description, End = end, Location = gEvent.Location, Start = start, Summary = gEvent.Summary, Id = gEvent.EventId }); }