36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using ContactService.Domain;
|
|
using ContactService.Infrastructure;
|
|
using IM.Commons.IntegrationEvents;
|
|
using MassTransit;
|
|
|
|
namespace ContactService.WebApi.Application.EventHandler
|
|
{
|
|
public class UserProfileUpdateHandler : IConsumer<UserProfileUpdateEvent>
|
|
{
|
|
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<UserProfileUpdateEvent> 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();
|
|
|
|
}
|
|
}
|
|
}
|