Exemple #1
0
        public async Task HandleAsync(IMessageContext context, AddEntry message)
        {
            var entry = new Whitelist {
                DomainName = message.DomainName
            };
            await _uow.InsertAsync(entry);

            foreach (var dto in message.ApplicationIds)
            {
                var entity = new WhitelistedDomainApplication {
                    DomainId = entry.Id, ApplicationId = dto
                };
                await _uow.InsertAsync(entity);
            }

            if (message.IpAddresses?.Length > 0)
            {
                foreach (var ip in message.IpAddresses)
                {
                    var entity = new WhitelistedDomainIp
                    {
                        DomainId    = entry.Id,
                        IpType      = IpType.Manual,
                        IpAddress   = IPAddress.Parse(ip),
                        StoredAtUtc = DateTime.UtcNow
                    };

                    await _uow.InsertAsync(entity);
                }
            }
            else
            {
                await LookupIps(message, entry);
            }
        }
        private async Task UpdateApplications(EditEntry message, Whitelist entry)
        {
            var dbApps = await _uow.ToListAsync <WhitelistedDomainApplication>("DomainId = @id", new { id = message.Id });

            //find new
            var newApps = message.ApplicationIds.Except(dbApps.Select(x => x.ApplicationId));

            foreach (var newApp in newApps)
            {
                var entity = new WhitelistedDomainApplication {
                    DomainId = entry.Id, ApplicationId = newApp
                };
                await _uow.InsertAsync(entity);
            }

            //find removed
            var removedApps = dbApps.Select(x => x.ApplicationId)
                              .Except(message.ApplicationIds)
                              .Select(x => dbApps.First(y => x == y.ApplicationId));

            foreach (var app in removedApps)
            {
                await _uow.DeleteAsync(app);
            }
        }