Exemple #1
0
        public List <EventWrapper> RemoveEvent(int eventId, ApiDateTime date, EventRemoveType type)
        {
            var events = new List <EventWrapper>();
            var evt    = _dataProvider.GetEventById(eventId);
            var cal    = _dataProvider.GetCalendarById(Convert.ToInt32(evt.CalendarId));

            if (evt.OwnerId.Equals(SecurityContext.CurrentAccount.ID) || CheckPermissions(evt, CalendarAccessRights.FullAccessAction, true) || CheckPermissions(cal, CalendarAccessRights.FullAccessAction, true))
            {
                if (type == EventRemoveType.AllSeries || evt.RecurrenceRule.Freq == Frequency.Never)
                {
                    _dataProvider.RemoveEvent(eventId);
                    return(events);
                }

                else if (type == EventRemoveType.Single)
                {
                    evt.RecurrenceRule.ExDates.Add(new RecurrenceRule.ExDate()
                    {
                        Date = date.UtcTime.Date, isDateTime = false
                    });
                }

                else if (type == EventRemoveType.AllFollowing)
                {
                    evt.RecurrenceRule.Until = date.UtcTime.Date;
                    if (!evt.AllDayLong)
                    {
                        evt.RecurrenceRule.Until = evt.RecurrenceRule.Until.Add(evt.UtcStartDate.TimeOfDay);
                    }
                }

                evt = _dataProvider.UpdateEvent(int.Parse(evt.Id), int.Parse(evt.CalendarId), evt.OwnerId, evt.Name, evt.Description,
                                                evt.UtcStartDate, evt.UtcEndDate, evt.RecurrenceRule, evt.AlertType, evt.AllDayLong,
                                                evt.SharingOptions.PublicItems);

                //define timeZone
                TimeZoneInfo timeZone;
                if (!CheckPermissions(cal, CalendarAccessRights.FullAccessAction, true))
                {
                    timeZone       = _dataProvider.GetTimeZoneForSharedEventsCalendar(SecurityContext.CurrentAccount.ID);
                    evt.CalendarId = SharedEventsCalendar.CalendarId;
                }
                else
                {
                    timeZone = _dataProvider.GetTimeZoneForCalendar(SecurityContext.CurrentAccount.ID, int.Parse(evt.CalendarId));
                }

                events = new EventWrapper(evt, SecurityContext.CurrentAccount.ID, timeZone).GetList(evt.UtcStartDate, date.UtcTime.AddMonths(_monthCount));
            }
            else
            {
                _dataProvider.UnsubscribeFromEvent(eventId, SecurityContext.CurrentAccount.ID);
            }

            return(events);
        }
        public List<EventWrapper> RemoveEvent(int eventId, ApiDateTime date, EventRemoveType type)
        {
            var events = new List<EventWrapper>();
            var evt = _dataProvider.GetEventById(eventId);
            var cal = _dataProvider.GetCalendarById(Convert.ToInt32(evt.CalendarId));

            if (evt.OwnerId.Equals(SecurityContext.CurrentAccount.ID) || CheckPermissions(evt, CalendarAccessRights.FullAccessAction, true) || CheckPermissions(cal, CalendarAccessRights.FullAccessAction, true))
            {
                if (type == EventRemoveType.AllSeries || evt.RecurrenceRule.Freq == Frequency.Never)
                {
                    _dataProvider.RemoveEvent(eventId);
                    return events;
                }

                else if (type == EventRemoveType.Single)
                    evt.RecurrenceRule.ExDates.Add(new RecurrenceRule.ExDate() { Date = date.UtcTime.Date, isDateTime = false });

                else if (type == EventRemoveType.AllFollowing)
                {
                    evt.RecurrenceRule.Until = date.UtcTime.Date;
                    if (!evt.AllDayLong)
                        evt.RecurrenceRule.Until = evt.RecurrenceRule.Until.Add(evt.UtcStartDate.TimeOfDay);
                }

                evt = _dataProvider.UpdateEvent(int.Parse(evt.Id), int.Parse(evt.CalendarId), evt.OwnerId, evt.Name, evt.Description,
                                              evt.UtcStartDate, evt.UtcEndDate, evt.RecurrenceRule, evt.AlertType, evt.AllDayLong,
                                              evt.SharingOptions.PublicItems);

                //define timeZone
                TimeZoneInfo timeZone;
                if (!CheckPermissions(cal, CalendarAccessRights.FullAccessAction, true))
                {
                    timeZone = _dataProvider.GetTimeZoneForSharedEventsCalendar(SecurityContext.CurrentAccount.ID);
                    evt.CalendarId = SharedEventsCalendar.CalendarId;
                }
                else
                    timeZone = _dataProvider.GetTimeZoneForCalendar(SecurityContext.CurrentAccount.ID, int.Parse(evt.CalendarId));

                events = new EventWrapper(evt, SecurityContext.CurrentAccount.ID, timeZone).GetList(evt.UtcStartDate, date.UtcTime.AddMonths(_monthCount));
            }
            else
                _dataProvider.UnsubscribeFromEvent(eventId, SecurityContext.CurrentAccount.ID);

            return events;
        }