Example #1
0
        /// <summary>
        /// Elimina un readmodel
        /// ?? gestire un flag di eliminato e memorizzare l'id dell'evento??
        /// </summary>
        /// <param name="e"></param>
        /// <param name="id"></param>
        /// <param name="notify"></param>
        public async Task DeleteAsync(DomainEvent e, TKey id, bool notify = false)
        {
            string[] topics = null;

            if (NotifySubscribers && typeof(ITopicsProvider).IsAssignableFrom(typeof(TModel)))
            {
                var model = await _storage.FindOneByIdAsync(id).ConfigureAwait(false);

                if (model == null)
                {
                    return;
                }

                topics = ((ITopicsProvider)model).GetTopics().ToArray();
            }

            var result = await _storage.DeleteAsync(id).ConfigureAwait(false);

            if (!result.Ok)
            {
                throw new CollectionWrapperException(FormatCollectionWrapperExceptionMessage(string.Format("Delete error on {0} :: {1}", typeof(TModel).FullName, id), e));
            }

            if (result.DocumentsAffected == 1 && ShouldSendNotification(e, notify))
            {
                await _notifyToSubscribers.Send(ReadModelUpdatedMessage.Deleted <TModel, TKey>(id, topics)).ConfigureAwait(false);
            }
        }
        /// <summary>
        /// Elimina un readmodel
        /// ?? gestire un flag di eliminato e memorizzare l'id dell'evento??
        /// </summary>
        /// <param name="e"></param>
        /// <param name="id"></param>
        /// <param name="notify"></param>
        public void Delete(DomainEvent e, TKey id, bool notify = false)
        {
            string[] topics = null;

            if (NotifySubscribers && typeof(ITopicsProvider).IsAssignableFrom(typeof(TModel)))
            {
                var model = _storage.FindOneById(id);
                if (model == null)
                {
                    return;
                }

                topics = ((ITopicsProvider)model).GetTopics().ToArray();
            }

            var result = _storage.Delete(id);

            if (!result.Ok)
            {
                throw new Exception(string.Format("Delete error on {0} :: {1}", typeof(TModel).FullName, id));
            }

            if (result.DocumentsAffected == 1)
            {
                if (!IsReplay && (notify || NotifySubscribers))
                {
                    _notifyToSubscribers.Send(ReadModelUpdatedMessage.Deleted <TModel, TKey>(id, topics));
                }
            }
        }