Esempio n. 1
0
        public async Task LogUserEventAsync(Guid userId, EventType type, DateTime?date = null)
        {
            var events = new List <IEvent>
            {
                new EventMessage(_currentContext)
                {
                    UserId       = userId,
                    ActingUserId = userId,
                    Type         = type,
                    Date         = date.GetValueOrDefault(DateTime.UtcNow)
                }
            };

            var orgAbilities = await _applicationCacheService.GetOrganizationAbilitiesAsync();

            var orgs = await _currentContext.OrganizationMembershipAsync(_organizationUserRepository, userId);

            var orgEvents = orgs.Where(o => CanUseEvents(orgAbilities, o.Id))
                            .Select(o => new EventMessage(_currentContext)
            {
                OrganizationId = o.Id,
                UserId         = userId,
                ActingUserId   = userId,
                Type           = type,
                Date           = DateTime.UtcNow
            });

            var providerAbilities = await _applicationCacheService.GetProviderAbilitiesAsync();

            var providers = await _currentContext.ProviderMembershipAsync(_providerUserRepository, userId);

            var providerEvents = providers.Where(o => CanUseProviderEvents(providerAbilities, o.Id))
                                 .Select(p => new EventMessage(_currentContext)
            {
                ProviderId   = p.Id,
                UserId       = userId,
                ActingUserId = userId,
                Type         = type,
                Date         = DateTime.UtcNow
            });

            if (orgEvents.Any() || providerEvents.Any())
            {
                events.AddRange(orgEvents);
                events.AddRange(providerEvents);
                await _eventWriteService.CreateManyAsync(events);
            }
            else
            {
                await _eventWriteService.CreateAsync(events.First());
            }
        }
Esempio n. 2
0
        public async Task LogUserEventAsync(Guid userId, EventType type, DateTime?date = null)
        {
            var events = new List <IEvent>
            {
                new EventMessage(_currentContext)
                {
                    UserId       = userId,
                    ActingUserId = userId,
                    Type         = type,
                    Date         = date.GetValueOrDefault(DateTime.UtcNow)
                }
            };

            var orgs = await _currentContext.OrganizationMembershipAsync(_organizationUserRepository, userId);

            var orgEvents = orgs
                            .Select(o => new EventMessage(_currentContext)
            {
                OrganizationId = o.Id,
                UserId         = userId,
                ActingUserId   = userId,
                Type           = type,
                Date           = DateTime.UtcNow
            });

            if (orgEvents.Any())
            {
                events.AddRange(orgEvents);
                await _eventWriteService.CreateManyAsync(events);
            }
            else
            {
                await _eventWriteService.CreateAsync(events.First());
            }
        }
Esempio n. 3
0
        public async Task LogUserEventAsync(Guid userId, EventType type)
        {
            var now    = DateTime.UtcNow;
            var events = new List <IEvent>
            {
                new EventMessage(_currentContext)
                {
                    UserId       = userId,
                    ActingUserId = userId,
                    Type         = type,
                    Date         = now
                }
            };

            var orgAbilities = await _applicationCacheService.GetOrganizationAbilitiesAsync();

            IEnumerable <IEvent> orgEvents;

            if (_currentContext.UserId.HasValue)
            {
                orgEvents = _currentContext.Organizations
                            .Where(o => CanUseEvents(orgAbilities, o.Id))
                            .Select(o => new EventMessage(_currentContext)
                {
                    OrganizationId = o.Id,
                    UserId         = userId,
                    ActingUserId   = userId,
                    Type           = type,
                    Date           = DateTime.UtcNow
                });
            }
            else
            {
                var orgs = await _organizationUserRepository.GetManyByUserAsync(userId);

                orgEvents = orgs
                            .Where(o => o.Status == OrganizationUserStatusType.Confirmed &&
                                   CanUseEvents(orgAbilities, o.OrganizationId))
                            .Select(o => new EventMessage(_currentContext)
                {
                    OrganizationId = o.OrganizationId,
                    UserId         = userId,
                    ActingUserId   = userId,
                    Type           = type,
                    Date           = DateTime.UtcNow
                });
            }

            if (orgEvents.Any())
            {
                events.AddRange(orgEvents);
                await _eventWriteService.CreateManyAsync(events);
            }
            else
            {
                await _eventWriteService.CreateAsync(events.First());
            }
        }