Example #1
0
        public async Task HandleAsync(RemarkActionCanceled @event)
        {
            await _handler
            .Run(async() =>
            {
                var remark = await _remarkServiceClient.GetAsync(@event.RemarkId);
                if (remark.HasValue)
                {
                    var isAuthor = remark.Value.Author.UserId == @event.UserId;
                    if (isAuthor)
                    {
                        return;
                    }

                    var isInFavorites = remark.Value.UserFavorites.Contains(@event.UserId);
                    if (isInFavorites)
                    {
                        return;
                    }
                }
                await _subscribersService.RemoveSubscriberAsync(@event.RemarkId, @event.UserId);
            })
            .OnError((ex, logger) =>
            {
                logger.Error(ex, $"Error occured while handling {@event.GetType().Name} event");
            })
            .ExecuteAsync();
        }
        public async Task HandleAsync(FavoriteRemarkDeleted @event)
        {
            await _handler
            .Run(async() =>
            {
                var remark = await _remarkServiceClient.GetAsync(@event.RemarkId);
                if (remark.HasValue)
                {
                    var isAuthor = remark.Value.Author.UserId == @event.UserId;
                    if (isAuthor)
                    {
                        return;
                    }

                    var isParticipant = Enumerable.Any <Participant>(remark.Value.Participants, p => p.User.UserId == @event.UserId);
                    if (isParticipant)
                    {
                        return;
                    }
                }
                await _subscribersService.RemoveSubscriberAsync(@event.RemarkId, @event.UserId);
            })
            .OnError((ex, logger) =>
            {
                logger.Error(ex, $"Error occured while handling {@event.GetType().Name} event");
            })
            .ExecuteAsync();
        }