示例#1
0
        public async Task PublishPhotosToRemarkAddedAsync(PhotosToRemarkAdded @event)
        {
            var remarkDto = await _remarkServiceClient.GetAsync <Remark>(@event.RemarkId);

            if (remarkDto.HasNoValue)
            {
                return;
            }
            var remark = remarkDto.Value;

            await PublishToAllAsync("photos_to_remark_added",
                                    new
            {
                remarkId  = remark.Id,
                newPhotos = remark.Photos
                            .Skip(remark.Photos.Count - 3)
                            .Take(3)
                            .Select(x => new
                {
                    size    = x.Size,
                    groupId = x.GroupId,
                    url     = x.Url
                })
            }
                                    );
        }
示例#2
0
        public async Task HandleAsync(PhotosFromRemarkRemoved @event)
        {
            await _handler
            .Run(async() =>
            {
                var remark = await _remarkRepository.GetByIdAsync(@event.RemarkId);
                if (remark.HasNoValue)
                {
                    return;
                }

                var remarkDto = await _remarkServiceClient.GetAsync <Remark>(@event.RemarkId);
                remark.Value.Photos.Clear();
                foreach (var photo in remarkDto.Value.Photos)
                {
                    remark.Value.Photos.Add(photo);
                }
                remark.Value.UpdatedAt = DateTime.UtcNow;
                await _remarkRepository.UpdateAsync(remark.Value);
                await _cache.AddAsync(remark.Value);
            })
            .OnError((ex, logger) =>
            {
                logger.Error(ex, $"Error occured while handling {@event.GetType().Name} event");
            })
            .ExecuteAsync();
        }
        public async Task HandleAsync(RemarkRenewed @event)
        {
            await _handler
            .Run(async() =>
            {
                var remark = await _remarkRepository.GetByIdAsync(@event.RemarkId);
                if (remark.HasNoValue)
                {
                    return;
                }

                var remarkDto          = await _remarkServiceClient.GetAsync <Remark>(@event.RemarkId);
                remark.Value.UpdatedAt = remarkDto.Value.UpdatedAt;
                remark.Value.State     = remarkDto.Value.State;
                remark.Value.States    = remarkDto.Value.States;
                remark.Value.Photos    = remarkDto.Value.Photos;
                remark.Value.Resolved  = false;
                await _remarkRepository.UpdateAsync(remark.Value);
                await _cache.AddAsync(remark.Value, addGeo: true);
            })
            .OnError((ex, logger) =>
            {
                logger.Error(ex, $"Error occured while handling {@event.GetType().Name} event");
            })
            .ExecuteAsync();
        }
示例#4
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();
        }
示例#5
0
        public async Task HandleAsync(RemarkAssignedToGroup @event)
        => await _handler
        .Run(async() =>
        {
            var remark = await _remarkRepository.GetByIdAsync(@event.RemarkId);
            if (remark.HasNoValue)
            {
                return;
            }

            var remarkDto          = await _remarkServiceClient.GetAsync <Remark>(@event.RemarkId);
            remark.Value.Group     = remarkDto.Value.Group;
            remark.Value.State     = remarkDto.Value.State;
            remark.Value.States    = remarkDto.Value.States;
            remark.Value.Assignee  = remarkDto.Value.Assignee;
            remark.Value.UpdatedAt = remarkDto.Value.UpdatedAt;
            await _remarkRepository.UpdateAsync(remark.Value);
            await _groupRemarkRepository.DeleteAllForRemarkAsync(@event.RemarkId);
            await _cache.AddAsync(remark.Value);
        })
        .OnError((ex, logger) =>
        {
            logger.Error(ex, $"Error occured while handling {@event.GetType().Name} event");
        })
        .ExecuteAsync();
        public async Task <Maybe <Remark> > GetAsync(Guid id)
        {
            var remark = await _provider.GetAsync(
                async() => await _remarkRepository.GetByIdAsync(id),
                async() => await _serviceClient.GetAsync <Remark>(id));

            if (remark.HasNoValue)
            {
                return(null);
            }
            if (remark.Value.Tags?.Any() == true)
            {
                remark.Value.SelectedTag = remark.Value.Tags.First().Name;
            }
            if (remark.Value.Group == null)
            {
                return(remark);
            }
            var group = await _groupRepository.GetAsync(remark.Value.Group.Id);

            remark.Value.Group.Criteria = group.Value.Criteria;
            remark.Value.Group.Members  = group.Value.Members.ToDictionary(x => x.UserId, x => x.Role);

            return(remark);
        }
 public async Task HandleAsync(RemarkEdited @event)
 => await _handler
 .Run(async() =>
 {
     var remark = await _remarkRepository.GetByIdAsync(@event.RemarkId);
     if (remark.HasNoValue)
     {
         return;
     }
     var remarkDto            = await _remarkServiceClient.GetAsync <Remark>(@event.RemarkId);
     remark.Value.Group       = remarkDto.Value.Group;
     remark.Value.Category    = remarkDto.Value.Category;
     remark.Value.Description = remarkDto.Value.Description;
     remark.Value.Location    = remarkDto.Value.Location;
     remark.Value.Tags        = remarkDto.Value.Tags;
     remark.Value.UpdatedAt   = remarkDto.Value.UpdatedAt;
     remark.Value.States      = remarkDto.Value.States;
     remark.Value.State       = remarkDto.Value.State;
     await _remarkRepository.UpdateAsync(remark.Value);
     await _cache.AddAsync(remark.Value);
 })
 .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();
        }
示例#9
0
 public async Task HandleAsync(RemarkCreated @event)
 {
     await _handler
     .Run(async() =>
     {
         var remark          = await _remarkServiceClient.GetAsync <Remark>(@event.RemarkId);
         remark.Value.Status = null;
         await _remarkRepository.AddAsync(remark.Value);
         await _remarkCache.AddAsync(remark.Value, addGeo: true, addLatest: true);
         await _userCache.AddRemarkAsync(remark.Value.Author.UserId, @event.RemarkId);
     })
     .OnError((ex, logger) =>
     {
         logger.Error(ex, $"Error occured while handling {@event.GetType().Name} event");
     })
     .ExecuteAsync();
 }
 protected async Task <Maybe <Remark> > GetRemarkAsync(Guid remarkId)
 => await _remarkServiceClient.GetAsync(remarkId);