public async Task HandleAsync(OrganizationCreated @event)
 {
     await _handler
     .Run(async() =>
     {
         var organization = await _groupServiceClient.GetOrganizationAsync <Organization>(@event.OrganizationId);
         organization.Value.GroupsCount  = organization.Value.Groups?.Count ?? 0;
         organization.Value.MembersCount = organization.Value.Members?.Count ?? 0;
         await _organizationRepository.AddAsync(organization.Value);
         await _organizationCache.AddAsync(organization.Value);
         var owner = organization.Value.Members.First(x => x.Role == "owner");
         var user  = await _userRepository.GetByIdAsync(owner.UserId);
         if (user.Value.Organizations == null)
         {
             user.Value.Organizations = new HashSet <UserOrganization>();
         }
         user.Value.Organizations.Add(new UserOrganization
         {
             Id       = organization.Value.Id,
             Name     = organization.Value.Name,
             Role     = owner.Role,
             IsActive = owner.IsActive
         });
         await _userRepository.EditAsync(user.Value);
         await _userCache.AddAsync(user.Value);
     })
     .OnError((ex, logger) =>
     {
         logger.Error(ex, $"Error occured while handling {@event.GetType().Name} event");
     })
     .ExecuteAsync();
 }
 public async Task HandleAsync(GroupCreated @event)
 {
     await _handler
     .Run(async() =>
     {
         var group = await _groupServiceClient.GetAsync <Group>(@event.GroupId);
         group.Value.MembersCount = group.Value.Members?.Count ?? 0;
         await _groupRepository.AddAsync(group.Value);
         await _groupCache.AddAsync(group.Value);
         if (!group.Value.OrganizationId.HasValue)
         {
             return;
         }
         var organization = await _organizationRepository.GetAsync(group.Value.OrganizationId.Value);
         if (organization.Value.Groups == null)
         {
             organization.Value.Groups = new List <Guid>();
         }
         organization.Value.Groups.Add(@event.GroupId);
         organization.Value.GroupsCount = organization.Value.Groups.Count;
         await _organizationRepository.UpdateAsync(organization.Value);
         await _organizationCache.AddAsync(organization.Value);
     })
     .OnError((ex, logger) =>
     {
         logger.Error(ex, $"Error occured while handling {@event.GetType().Name} event");
     })
     .ExecuteAsync();
 }
示例#3
0
 public async Task HandleAsync(OrganizationCreated @event)
 {
     await _handler
     .Run(async() =>
     {
         var organization = await _groupServiceClient.GetOrganizationAsync <Organization>(@event.OrganizationId);
         organization.Value.GroupsCount  = organization.Value.Groups?.Count ?? 0;
         organization.Value.MembersCount = organization.Value.Members?.Count ?? 0;
         await _organizationRepository.AddAsync(organization.Value);
         await _cache.AddAsync(organization.Value);
     })
     .OnError((ex, logger) =>
     {
         logger.Error(ex, $"Error occured while handling {@event.GetType().Name} event");
     })
     .ExecuteAsync();
 }
 public async Task HandleAsync(GroupCreated @event)
 {
     await _handler
     .Run(async() =>
     {
         var group = await _groupServiceClient.GetAsync <Group>(@event.GroupId);
         group.Value.MembersCount = group.Value.Members.Count;
         await _groupRepository.AddAsync(group.Value);
         await _groupCache.AddAsync(group.Value);
         var owner = group.Value.Members.First(x => x.Role == "owner");
         var user  = await _userRepository.GetByIdAsync(owner.UserId);
         if (user.Value.Groups == null)
         {
             user.Value.Groups = new HashSet <UserGroup>();
         }
         user.Value.Groups.Add(new UserGroup
         {
             Id       = group.Value.Id,
             Name     = group.Value.Name,
             Role     = owner.Role,
             IsActive = owner.IsActive
         });
         await _userRepository.EditAsync(user.Value);
         await _userCache.AddAsync(user.Value);
         if (!group.Value.OrganizationId.HasValue)
         {
             return;
         }
         var organization = await _organizationRepository.GetAsync(group.Value.OrganizationId.Value);
         if (organization.Value.Groups == null)
         {
             organization.Value.Groups = new List <Guid>();
         }
         organization.Value.Groups.Add(@event.GroupId);
         organization.Value.GroupsCount = organization.Value.Groups.Count;
         await _organizationRepository.UpdateAsync(organization.Value);
         await _organizationCache.AddAsync(organization.Value);
     })
     .OnError((ex, logger) =>
     {
         logger.Error(ex, $"Error occured while handling {@event.GetType().Name} event");
     })
     .ExecuteAsync();
 }
 public async Task HandleAsync(MemberAddedToOrganization @event)
 {
     await _handler
     .Run(async() =>
     {
         var organization = await _organizationRepository.GetAsync(@event.OrganizationId);
         var user         = await _userRepository.GetByIdAsync(@event.MemberId);
         organization.Value.Members.Add(new Member
         {
             UserId   = user.Value.UserId,
             Name     = user.Value.Name,
             Role     = @event.Role,
             IsActive = true
         });
         organization.Value.MembersCount++;
         await _organizationRepository.UpdateAsync(organization.Value);
         await _organizationCache.AddAsync(organization.Value);
         var member = organization.Value.Members.First(x => x.UserId == @event.MemberId);
         if (user.Value.Organizations == null)
         {
             user.Value.Organizations = new HashSet <UserOrganization>();
         }
         user.Value.Organizations.Add(new UserOrganization
         {
             Id       = organization.Value.Id,
             Name     = organization.Value.Name,
             Role     = member.Role,
             IsActive = member.IsActive
         });
         await _userRepository.EditAsync(user.Value);
         await _userCache.AddAsync(user.Value);
     })
     .OnError((ex, logger) =>
     {
         logger.Error(ex, $"Error occured while handling {@event.GetType().Name} event");
     })
     .ExecuteAsync();
 }
 public async Task HandleAsync(MemberAddedToOrganization @event)
 {
     await _handler
     .Run(async() =>
     {
         var organization = await _organizationRepository.GetAsync(@event.OrganizationId);
         var user         = await _userRepository.GetByIdAsync(@event.MemberId);
         organization.Value.Members.Add(new Member
         {
             UserId   = user.Value.UserId,
             Name     = user.Value.Name,
             Role     = @event.Role,
             IsActive = true
         });
         organization.Value.MembersCount++;
         await _organizationRepository.UpdateAsync(organization.Value);
         await _cache.AddAsync(organization.Value);
     })
     .OnError((ex, logger) =>
     {
         logger.Error(ex, $"Error occured while handling {@event.GetType().Name} event");
     })
     .ExecuteAsync();
 }