public async Task <IEnumerable <DHCPv4Listener> > GetDHCPv4Listener() { var result = await DHCPv4Interfaces.AsQueryable() .OrderBy(x => x.Name).ToListAsync(); List <DHCPv4Listener> listeners = new List <DHCPv4Listener>(result.Count); foreach (var item in result) { var listener = new DHCPv4Listener(); listener.Load(new DomainEvent[] { new DHCPv4ListenerCreatedEvent { Id = item.Id, Name = item.Name, InterfaceId = item.InterfaceId, Address = item.IPv4Address, } }); listeners.Add(listener); } return(listeners); }
public async Task <Boolean> Project(IEnumerable <DomainEvent> events) { Boolean hasChanges = true; foreach (var item in events) { Boolean handled = true; switch (item) { case NotificationPipelineCreatedEvent e: NotificationPipelines.Add(new NotificationPipelineOverviewEntry { Id = e.Id, Name = e.Name }); break; case NotificationPipelineDeletedEvent e: var existingPipeline = await NotificationPipelines.AsQueryable().FirstAsync(x => x.Id == e.Id); NotificationPipelines.Remove(existingPipeline); break; case DHCPv6ListenerCreatedEvent e: DHCPv6Interfaces.Add(new DHCPv6InterfaceDataModel { Id = e.Id, InterfaceId = e.InterfaceId, IPv6Address = e.Address, Name = e.Name, }); break; case DHCPv6ListenerDeletedEvent e: var existingv6Interface = await DHCPv6Interfaces.AsQueryable().FirstAsync(x => x.Id == e.Id); DHCPv6Interfaces.Remove(existingv6Interface); break; case DHCPv4ListenerCreatedEvent e: DHCPv4Interfaces.Add(new DHCPv4InterfaceDataModel { Id = e.Id, InterfaceId = e.InterfaceId, IPv4Address = e.Address, Name = e.Name, }); break; case DHCPv4ListenerDeletedEvent e: var existingv4Interface = await DHCPv4Interfaces.AsQueryable().FirstAsync(x => x.Id == e.Id); DHCPv4Interfaces.Remove(existingv4Interface); break; default: hasChanges = false; handled = false; break; } if (handled == true) { continue; } Boolean?dhcpv6Related = await ProjectDHCPv6PacketAndLeaseRelatedEvents(item); if (dhcpv6Related.HasValue == true) { if (hasChanges == false && dhcpv6Related.Value == true) { hasChanges = true; } } else { Boolean?dhcpv4Related = await ProjectDHCPv4PacketAndLeaseRelatedEvents(item); if (dhcpv4Related.HasValue == true && hasChanges == false && dhcpv4Related.Value == true) { hasChanges = true; } } } if (hasChanges == false) { return(true); } return(await SaveChangesAsyncInternal()); }