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(); }
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(MemberAddedToGroup @event) { await _handler .Run(async() => { var group = await _groupRepository.GetAsync(@event.GroupId); var user = await _userRepository.GetByIdAsync(@event.MemberId); group.Value.Members.Add(new Member { UserId = user.Value.UserId, Name = user.Value.Name, Role = @event.Role, IsActive = true }); group.Value.MembersCount++; await _groupRepository.UpdateAsync(group.Value); await _groupCache.AddAsync(group.Value); var member = group.Value.Members.First(x => x.UserId == @event.MemberId); 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 = 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(MemberAddedToGroup @event) { await _handler .Run(async() => { var group = await _groupRepository.GetAsync(@event.GroupId); var user = await _userRepository.GetByIdAsync(@event.MemberId); group.Value.Members.Add(new Member { UserId = user.Value.UserId, Name = user.Value.Name, Role = @event.Role, IsActive = true }); group.Value.MembersCount++; await _groupRepository.UpdateAsync(group.Value); await _cache.AddAsync(group.Value); }) .OnError((ex, logger) => { logger.Error(ex, $"Error occured while handling {@event.GetType().Name} event"); }) .ExecuteAsync(); }