diff --git a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Users/BlogUserSynchronizer.cs b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Users/BlogUserSynchronizer.cs new file mode 100644 index 0000000000..6000d121f9 --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Users/BlogUserSynchronizer.cs @@ -0,0 +1,39 @@ +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Entities.Events.Distributed; +using Volo.Abp.EventBus.Distributed; +using Volo.Abp.Users; + +namespace Volo.Blogging.Users +{ + public class BlogUserSynchronizer : + IDistributedEventHandler>, + ITransientDependency + { + protected IBlogUserRepository UserRepository { get; } + protected IBlogUserLookupService UserLookupService { get; } + + public BlogUserSynchronizer(IBlogUserRepository userRepository, IBlogUserLookupService userLookupService) + { + UserRepository = userRepository; + UserLookupService = userLookupService; + } + + public async Task HandleEventAsync(EntityUpdatedEto eventData) + { + var user = await UserRepository.FindAsync(eventData.Entity.Id); + if (user == null) + { + //TODO: Why needed (ask to @ebicoglu)? + user = await UserLookupService.FindByIdAsync(eventData.Entity.Id); + if (user == null) + { + return; + } + } + + user.Update(eventData.Entity); + await UserRepository.UpdateAsync(user); + } + } +}