/// <summary> /// Gets an instance of this ViewModel for a single Hypervisor. /// </summary> /// <param name="db">The database context to use for data /// gathering.</param> /// <param name="predicate">The predicate to use when filtering for the /// Hypervisor to reference.</param> /// <returns>An initialized view model instance, or null if no data is /// found.</returns> public static new HypervisorDetailsViewModel SelectSingle(MigrationToolEntities db, Func <Hypervisor, bool> predicate) { var item = db.Hypervisors .Include("Notes") .Include("TagsMetas") .Include("TagsMetas.Tag") .Include("HypervisorGroup") .Include("HypervisorType") .Include("HypervisorWorkloadProfile") .Where(predicate) .Select(x => new { Hypervisor = x }) .SingleOrDefault(); if (item != null) { return(new HypervisorDetailsViewModel(item.Hypervisor)); } else { return(null); } }
/// <summary> /// Gets a collection of instances of this view model referencing the /// DataStore indicated by the provided predicate. /// </summary> /// <param name="db">The database context to use for data /// gathering.</param> /// <param name="predicate">The predicate to use when filtering for /// DataStore to reference.</param> /// <returns>A collection of initialized view model objects.</returns> public static IEnumerable <DataStoreListIndexViewModel> SelectMany(MigrationToolEntities db, Func <DataStore, bool> predicate) { var list = db.DataStores .AsQueryable() .Include("Notes") .Include("TagsMetas") .Include("TagsMetas.Tag") .Include("DataStoreGroup") .Include("DataStoreCategory"); if (predicate != null) { list = list.Where(predicate).AsQueryable(); } return(list.OrderBy(x => x.Name) .Select(x => new { DataStore = x, ActiveVirtualHardDriveCount = x.VirtualHardDrives .Where(y => !y.Inactive) .Count(), ActiveVirtualMachineCount = x.VirtualHardDrives .SelectMany(y => y.VirtualMachines .Where(z => !z.Inactive)) .Distinct() .Count() }) .AsEnumerable() .Select(x => new DataStoreListIndexViewModel(x.DataStore, x.ActiveVirtualHardDriveCount, x.ActiveVirtualMachineCount)) .ToList()); }
/// <summary> /// Gets a collection of instances of this view model referencing the /// Hypervisor indicated by the provided predicate. /// </summary> /// <param name="db">The database context to use for data /// gathering.</param> /// <param name="predicate">The predicate to use when filtering for /// Hypervisor to reference.</param> /// <returns>A collection of initialized view model objects.</returns> public static IEnumerable <HypervisorListIndexViewModel> SelectMany(MigrationToolEntities db, Func <Hypervisor, bool> predicate) { var list = db.Hypervisors .AsQueryable() .Include("Notes") .Include("TagsMetas") .Include("TagsMetas.Tag") .Include("HypervisorType") .Include("HypervisorGroup"); if (predicate != null) { list = list.Where(predicate).AsQueryable(); } return(list.OrderBy(x => x.Name) .Select(x => new { Hypervisors = x, ActiveVirtualMachineCount = x.VirtualMachines .Where(z => !z.Inactive) .Distinct() .Count() }) .AsEnumerable() .Select(x => new HypervisorListIndexViewModel(x.Hypervisors, x.ActiveVirtualMachineCount)) .ToList()); }
/// <summary> /// Gets an instance of this view model for a single /// HypervisorController. /// </summary> /// <param name="db">The database context to use for data /// gathering.</param> /// <param name="predicate">The predicate to use when filtering for the /// HypervisorController to reference.</param> /// <returns>An initialized view model instance, or null if no data is /// found.</returns> public static HypervisorControllerReferenceViewModel SelectSingle(MigrationToolEntities db, Func <HypervisorController, bool> predicate) { var item = db.HypervisorControllers .AsNoTracking() .Where(predicate) .SingleOrDefault(); if (item != null) { return(new HypervisorControllerReferenceViewModel(item)); } else { return(null); } }
/// <summary> /// Gets an instance of this view model for a single /// DataStore. /// </summary> /// <param name="db">The database context to use for data /// gathering.</param> /// <param name="predicate">The predicate to use when filtering for the /// DataStore to reference.</param> /// <returns>An initialized view model instance, or null if no data is /// found.</returns> public static DataStoreReferenceViewModel SelectSingle(MigrationToolEntities db, Func <DataStore, bool> predicate) { var item = db.DataStores .AsNoTracking() .Where(predicate) .SingleOrDefault(); if (item != null) { return(new DataStoreReferenceViewModel(item)); } else { return(null); } }
public HomeViewModel(MigrationToolEntities db) { this.DataSources = db.DataSources .Where(x => !x.Inactive && x.DataSourcesStatus.Count() > 0) .Select(x => x.DataSourcesStatus .Where(y => y.CreateDate == x.DataSourcesStatus.Max(z => z.CreateDate)).FirstOrDefault()) .OrderBy(x => x.DataSource.Name).ToList() .Select(x => new SourceData { Name = x.DataSource.Name, Succcess = x.Success, CreateDate = x.CreateDate, Duration = new TimeSpan(0, 0, 0, 0, x.Duration) }) .ToList(); }
/// <summary> /// Gets an instance of this ViewModel for a single DataStoreGroup. /// </summary> /// <param name="db">The database context to use for data /// gathering.</param> /// <param name="predicate">The predicate to use when filtering for the /// DataStoreGroup to reference.</param> /// <returns>An initialized view model instance, or null if no data is /// found.</returns> public static new DataStoreGroupDetailsViewModel SelectSingle(MigrationToolEntities db, Func <DataStoreGroup, bool> predicate) { var item = db.DataStoreGroups .Include("Notes") .Include("TagsMetas") .Include("TagsMetas.Tag") .Include("DataStores") .Include("DataStores.VirtualHardDrives") .Include("DataStores.VirtualHardDrives.VirtualMachines") .Where(predicate) .Select(x => new { DataStoreGroup = x, ActiveDataStoreCount = x.DataStores .Where(y => !y.Inactive) .Count(), TotalDataStoreCount = x.DataStores .Count(), ActiveVirtualMachineCount = x.DataStores .Where(y => !y.Inactive) .SelectMany(y => y.VirtualHardDrives) .Distinct() .Where(y => !y.Inactive) .SelectMany(y => y.VirtualMachines) .Distinct() .Where(y => !y.Inactive) .Count(), TotalVirtualMachineCount = x.DataStores .SelectMany(y => y.VirtualHardDrives) .Distinct() .SelectMany(y => y.VirtualMachines) .Distinct() .Count() }) .SingleOrDefault(); if (item != null) { return(new DataStoreGroupDetailsViewModel(item.DataStoreGroup, item.ActiveDataStoreCount, item.TotalDataStoreCount, item.ActiveVirtualMachineCount, item.TotalVirtualMachineCount)); } else { return(null); } }
/// <summary> /// Gets a collection of instances of this view model referencing the /// HypervisorGroups indicated by the provided predicate. /// </summary> /// <param name="db">The database context to use for data /// gathering.</param> /// <param name="predicate">The predicate to use when filtering for /// HypervisorGroups to reference.</param> /// <returns>A collection of initialized view model objects.</returns> public static IEnumerable <HypervisorGroupListNutanixViewModel> SelectMany(MigrationToolEntities db, Func <HypervisorGroup, bool> predicate) { var list = db.HypervisorGroups .AsQueryable() .Include("Hypervisors") .Include("Hypervisors.VirtualMachines") .Include("Hypervisors.DataStores") .Include("Hypervisors.DataStores.DataStoreGroup"); if (predicate != null) { list = list.Where(predicate).AsQueryable(); } return(list.OrderBy(x => x.Name) .AsEnumerable() .Select(x => new HypervisorGroupListNutanixViewModel(x)) .ToList()); }
/// <summary> /// Gets an instance of this ViewModel for a single /// HypervisorController. /// </summary> /// <param name="db">The database context to use for data /// gathering.</param> /// <param name="predicate">The predicate to use when filtering for the /// HypervisorController to reference.</param> /// <returns>An initialized view model instance, or null if no data is /// found.</returns> public static new HypervisorControllerDetailsViewModel SelectSingle(MigrationToolEntities db, Func <HypervisorController, bool> predicate) { var item = db.HypervisorControllers .Include("Notes") .Include("TagsMetas") .Include("TagsMetas.Tag") .Where(predicate) .Select(x => new { HypervisorController = x, TotalHypervisorGroupCount = x.HypervisorGroups.Count() }) .SingleOrDefault(); if (item != null) { return(new HypervisorControllerDetailsViewModel(item.HypervisorController, item.TotalHypervisorGroupCount)); } else { return(null); } }
/// <summary> /// Hides and disables the ability to get single instances of this view /// model. /// </summary> /// <param name="db">The database context to use for data /// gathering.</param> /// <param name="predicate">The predicate to use when filtering for the /// DataStore to reference.</param> /// <returns>An initialized view model instance, or null if no data is /// found.</returns> private static new DataStoreListIndexViewModel SelectSingle(MigrationToolEntities db, Func <DataStore, bool> predicate) { throw new NotImplementedException(); }
/// <summary> /// Hides and disables the ability to get single instances of this view /// model. /// </summary> /// <param name="db">The database context to use for data /// gathering.</param> /// <param name="predicate">The predicate to use when filtering for the /// HypervisorController to reference.</param> /// <returns>An initialized view model instance, or null if no data is /// found.</returns> private static new HypervisorControllerListIndexViewModel SelectSingle(MigrationToolEntities db, Func <HypervisorController, bool> predicate) { throw new NotImplementedException(); }
/// <summary> /// Gets a collection of instances of this view model referencing the /// HypervisorControllers indicated by the provided predicate. /// </summary> /// <param name="db">The database context to use for data /// gathering.</param> /// <param name="predicate">The predicate to use when filtering for /// HypervisorControllers to reference.</param> /// <returns>A collection of initialized view model objects.</returns> public static IEnumerable <HypervisorControllerListIndexViewModel> SelectMany(MigrationToolEntities db, Func <HypervisorController, bool> predicate) { var list = db.HypervisorControllers .AsQueryable() .Include("Notes") .Include("TagsMetas") .Include("TagsMetas.Tag"); if (predicate != null) { list.Where(predicate); } return(list .OrderBy(x => x.Inactive) .ThenBy(x => x.Name) .Select(x => new { HypervisorController = x, ActiveHypervisorGroupCount = x.HypervisorGroups.Where(y => !y.Inactive).Count() }) .AsEnumerable() .Select(x => new HypervisorControllerListIndexViewModel(x.HypervisorController, x.ActiveHypervisorGroupCount)) .ToList()); }
/// <summary> /// Hides and disables the ability to get single instances of this view /// model. /// </summary> /// <param name="db">The database context to use for data /// gathering.</param> /// <param name="predicate">The predicate to use when filtering for the /// HypervisorGroup to reference.</param> /// <returns>An initialized view model instance, or null if no data is /// found.</returns> private static new HypervisorGroupListNutanixViewModel SelectSingle(MigrationToolEntities db, Func <HypervisorGroup, bool> predicate) { throw new NotImplementedException(); }