/// <inheritdoc /> /// <summary> /// Create new event /// </summary> /// <param name="evt"></param> /// <returns></returns> public async Task <ResultModel> PushEventAsync(GetEventViewModel evt) { var response = new ResultModel(); if (!Authorized) { return(response); } var googleEvent = GoogleCalendarMapper.Map(evt); try { var request = _calendarService.Events.Insert(googleEvent, CalendarName); var requestResult = await request.ExecuteAsync(); response.IsSuccess = true; response.Result = requestResult.Id; await _settingsService.SetEventAttributeAsync(evt.Id, $"{nameof(GoogleCalendarProvider)}_evtId", requestResult.Id); } catch (Exception e) { response.Errors.Add(new ErrorModel(e.Message)); } return(response); }
/// <inheritdoc /> /// <summary> /// Update event /// </summary> /// <param name="evt"></param> /// <param name="evtId"></param> /// <returns></returns> public async Task <ResultModel> UpdateEventAsync(GetEventViewModel evt, string evtId) { var response = new ResultModel(); if (!Authorized || evtId.IsNullOrEmpty()) { return(response); } try { var request = _calendarService.Events.Get(CalendarName, evtId); var googleEvent = await request.ExecuteAsync(); var updateRequest = _calendarService.Events.Update(GoogleCalendarMapper.Map(googleEvent, evt), CalendarName, evtId); await updateRequest.ExecuteAsync(); response.IsSuccess = true; } catch (Exception e) { response.Errors.Add(new ErrorModel(string.Empty, e.Message)); } return(response); }