using ContactService.Domain; using ContactService.Infrastructure; using IM.Commons.IntegrationEvents; using MassTransit; namespace ContactService.WebApi.Application.EventHandler { public class UserProfileUpdateHandler : IConsumer { private readonly ContactDbContext contactDb; private readonly IFriendReposity reposity; public UserProfileUpdateHandler(ContactDbContext contactDb, IFriendReposity reposity) { this.contactDb = contactDb; this.reposity = reposity; } public async Task Consume(ConsumeContext context) { var @event = context.Message; var friends = await reposity.FindByTargetAsync(@event.UserId); foreach (var friend in friends) { friend.UpdateUserInfo( new Domain.ValueObjects.UserProfile( @event.UserId, @event.Avatar, @event.NickName)); } await contactDb.SaveChangesAsync(); } } }