예제 #1
0
 public async Task CalendarService_SucessfullyDeleteAddedEvent(GoogleCalendarService service, string eventId)
 {
     try
     {
         await service.DeleteEvent(eventId);
     }
     catch (Exception ex)
     {
         Assert.Fail("Failed to delete event: " + ex.Message);
     }
 }
예제 #2
0
        public HttpResponseMessage Delete(int Id)
        {
            int UserId = User.Identity.GetId().Value;

            calendarService.DeleteTimeBlock(Id, UserId);

            Task.Run(() =>
            {
                UserConnectedCalendars userCalendar = exCalHelperService.CheckConnectedCalendars(UserId);
                if (userCalendar.hasGoogle)
                {
                    googleCalendarService.DeleteEvent(UserId, Id);
                }
                if (userCalendar.hasMicrosoft)
                {
                    msCalService.DeleteEvent(UserId, Id);
                }
            });

            return(Request.CreateResponse(HttpStatusCode.OK, new SuccessResponse()));
        }
예제 #3
0
        // Save received event (already validated by edit view model) to db
        // If SaveEventMsg.SaveChangeOnline true, then also save event to / delete event from google calendar
        private async void OnModifyEventReceived(ModifyEventMsg m)
        {
            var eventToModify = m.Event;
            var service       = new GoogleCalendarService();

            try
            {
                // Modify local db and possiblely google calendar based on action
                switch (m.Action)
                {
                case EventModifyAction.Add:
                    string googleCalendarEventId = null;
                    var    targetAccountId       = eventToModify.AID;
                    // Apply changes online first so any failure will prevent changes from being saved locally
                    if (LoggedIn && m.SaveChangeOnline)
                    {
                        googleCalendarEventId = await service.AddEvent(eventToModify.ToEvent());
                    }
                    // Event was successfully persisted on Google Calendar, update account and id
                    if (!googleCalendarEventId.IsNullOrEmpty())
                    {
                        var accounts        = _dbs.GetAvailableAccounts();
                        var lastSyncAccount = accounts.Where(a => a.AccId > 1)
                                              .OrderByDescending(a => a.LastSync)
                                              .FirstOrDefault();
                        if (lastSyncAccount == null)
                        {
                            throw new DataException("Couldn't find target Google Calendar account");
                        }
                        targetAccountId   = lastSyncAccount.AccId;
                        eventToModify.GID = googleCalendarEventId;
                    }
                    // Save changes locally
                    await _dbs.AddEvent(eventToModify, targetAccountId);

                    // Switch view to edit just created event
                    Messenger.Base.Send(eventToModify);
                    break;

                case EventModifyAction.Update:
                    if (LoggedIn && m.SaveChangeOnline)
                    {
                        await service.UpdateEvent(eventToModify.ToEvent());
                    }
                    await _dbs.UpdateEvent(eventToModify, eventToModify.EID);

                    break;

                case EventModifyAction.Delete:
                    if (LoggedIn && m.SaveChangeOnline)
                    {
                        await service.DeleteEvent(eventToModify.GID);
                    }
                    _dbs.DeleteEvent(eventToModify.EID);
                    break;

                default:
                    SendModifyEventStatus(success: false, msg: "Unknown action received");
                    return;
                }
            }
            catch (DataException ex)
            {
                SendModifyEventStatus(success: false, msg: ex.Message);
                return;
            }
            catch (Google.GoogleApiException)
            {
                SendModifyEventStatus(success: false, msg: "Unable to apply changes online. If error persists, consider modifying event locally");
                return;
            }
            SendModifyEventStatus(success: true, deleted: m.Action == EventModifyAction.Delete);
            RefreshEvents(viewableEventsNum);

            // Update tree view if opened
            Messenger.Base.Send(new UpdateTreeViewMsg
            {
                ModifiedEvent = m.Event,
                Action        = m.Action
            });
        }