Beispiel #1
0
        public Task Delete(string entityId, DateTime version)
        {
            var entityWithId = Get(new[] { entityId }, NullLoadEntityLogger.Instance).Result.SingleOrDefault();

            if (entityWithId == null)
            {
                return(Task.FromResult(0));
            }

            using (var contact = entityWithId.Entity)
            {
                if (!contact.Inner.Birthday.Equals(new DateTime(4501, 1, 1, 0, 0, 0)))
                {
                    try
                    {
                        Byte[] ba = contact.Inner.GetPropertySafe(PR_ASSOCIATED_BIRTHDAY_APPOINTMENT_ID);
                        string birthdayAppointmentItemID       = BitConverter.ToString(ba).Replace("-", string.Empty);
                        AppointmentItemWrapper birthdayWrapper = new AppointmentItemWrapper((AppointmentItem)_mapiNameSpace.GetItemFromID(birthdayAppointmentItemID),
                                                                                            entryId => (AppointmentItem)_mapiNameSpace.GetItemFromID(birthdayAppointmentItemID));
                        birthdayWrapper.Inner.Delete();
                    }
                    catch (COMException ex)
                    {
                        s_logger.Error("Could not delete associated Birthday Appointment.", ex);
                    }
                }
                contact.Inner.Delete();
            }

            return(Task.FromResult(0));
        }
        private async Task DeleteAppointment(AppointmentItemWrapper item, Dictionary <string, IEntityRelationData <string, DateTime, WebResourceName, string> > relations)
        {
            IEntityRelationData <string, DateTime, WebResourceName, string> relation;

            if (relations.TryGetValue(item.Inner.EntryID, out relation))
            {
                await _btypeRepository.TryDelete(relation.BtypeId, relation.BtypeVersion, NullEventSynchronizationContext.Instance);

                relations.Remove(item.Inner.EntryID);
            }
            item.Inner.Delete();
        }
        private void SwitchEventCategories(ChangedOptions changedOption, string oldCategory, string newCategory, string eventId)
        {
            using (var eventWrapper = new AppointmentItemWrapper(
                       (AppointmentItem)_session.GetItemFromID(eventId, changedOption.New.OutlookFolderStoreId),
                       entryId => (AppointmentItem)_session.GetItemFromID(entryId, changedOption.New.OutlookFolderStoreId)))
            {
                var categories = eventWrapper.Inner.Categories
                                 .Split(new[] { CultureInfo.CurrentCulture.TextInfo.ListSeparator }, StringSplitOptions.RemoveEmptyEntries)
                                 .Select(c => c.Trim());

                eventWrapper.Inner.Categories = string.Join(
                    CultureInfo.CurrentCulture.TextInfo.ListSeparator,
                    categories
                    .Except(new[] { oldCategory })
                    .Concat(new[] { newCategory })
                    .Distinct());

                eventWrapper.Inner.Save();
            }
        }