/// <summary> /// Initializes a new instance of the /// <see cref="HypervisorGroupListCapacityViewModel"/> class. /// </summary> /// <param name="model">The HypervisorGroup to reference.</param> /// <param name="activeVirtualMachineCount">The number of active /// VirtualMachines in the HypervisorGroup.</param> public HypervisorGroupListCapacityViewModel(HypervisorGroup model, int activeVirtualMachineCount) : base(model) { this.ReadEntityProperties(model); this.ActiveVirtualMachineCount = activeVirtualMachineCount; }
public ActionResult Create(HypervisorGroup hypervisorgroup) { if (ModelState.IsValid) { hypervisorgroup.Id = Guid.NewGuid(); hypervisorgroup.CreatedDate = DateTime.Now; hypervisorgroup.LastUpdated = hypervisorgroup.CreatedDate; if (hypervisorgroup.HighAvailabilityCalculationType != 1) { hypervisorgroup.HighAvailabilityReservedHypervisors = 0; } if (hypervisorgroup.HighAvailabilityCalculationType != 2) { hypervisorgroup.HighAvailabilityReservedPercentage = 0; } this.db.HypervisorGroups.AddObject(hypervisorgroup); this.db.SaveChanges(); return(this.RedirectToAction("Details", new { id = hypervisorgroup.Id })); } ViewBag.HypervisorGroupType_Id_Select = new SelectList(this.db.HypervisorGroupTypes.OrderBy(x => x.Name), "Id", "Name", hypervisorgroup.HypervisorGroupType_Id); return(this.View(hypervisorgroup)); }
public ActionResult DeleteConfirmed(Guid id) { HypervisorGroup hypervisorgroup = this.db.HypervisorGroups.Single(h => h.Id == id); this.db.HypervisorGroups.DeleteObject(hypervisorgroup); this.db.SaveChanges(); return(this.RedirectToAction("Index")); }
/// <summary> /// Populates properties on the view model from an instance of the /// HypervisorGroup class. /// </summary> /// <param name="model">The HypervisorGroup to reference.</param> private void ReadEntityProperties(HypervisorGroup model) { this.TotalCapacity = model.TotalCapacity; this.UsedCapacity = model.UsedCapacity; this.UsedCapacityPercent = model.UsedCapacityPercent; this.CapacityConstraint = FormatHelper.CapacityConstraintBitsToString(model.CapacityConstraintBits); this.CapacityConstraintBits = model.CapacityConstraintBits; }
/// <summary> /// Initializes a new instance of the /// <see cref="HypervisorGroupListIndexViewModel"/> class. /// </summary> /// <param name="model">The HypervisorGroup to reference.</param> /// <param name="virtualMachineCount">The number of active /// Virtual Machines related to the HypervisorGroup.</param> /// <param name="hypervisorCount">The number of active /// Hypervisors related to the HypervisorGroup.</param> private HypervisorGroupListIndexViewModel(HypervisorGroup model, int virtualMachineCount, int hypervisorCount) : base(model) { // Properties from the entity, notes and tags. this.ReadEntityProperties(model); // Related entities. this.VirtualMachineCount = virtualMachineCount; this.HypervisorCount = hypervisorCount; }
public ActionResult Edit(Guid id) { HypervisorGroup hypervisorgroup = this.db.HypervisorGroups.Single(h => h.Id == id); if (hypervisorgroup == null) { return(this.HttpNotFound()); } ViewBag.HypervisorGroupType_Id_Select = new SelectList(this.db.HypervisorGroupTypes.OrderBy(x => x.Name), "Id", "Name", hypervisorgroup.HypervisorGroupType_Id); return(this.View(hypervisorgroup)); }
/// <summary> /// Initializes a new instance of the /// <see cref="HypervisorGroupDetailsViewModel"/> class. /// </summary> /// <param name="model">The HypervisorGroup to reference.</param> public HypervisorGroupDetailsViewModel(HypervisorGroup model) : base(model) { // Properties from the entity, notes and tags. this.ReadEntityProperties(model); this.TotalHypervisorCount = model.Hypervisors.Count(); this.TotalVirtualMachineCount = model.Hypervisors .SelectMany(x => x.VirtualMachines) .Count(); }
/// <summary> /// Populates properties on the view model from an instance of the /// HypervisorGroup class. /// </summary> /// <param name="model">The HypervisorGroup to reference.</param> private void ReadEntityProperties(HypervisorGroup model) { // Properties from the entity. this.Id = model.Id; this.Name = model.Name; this.Inactive = model.Inactive; this.UsedCapacityPercent = model.UsedCapacityPercent; this.TotalCapacity = model.TotalCapacity; this.UsedCapacity = model.UsedCapacity; // Notes and Tags. this.Notes = new NoteCollectionListViewModel(model.Notes); this.Tags = new TagCollectionListViewModel(model.TagsMetas); }
/// <summary> /// Populates properties on the view model from an instance of the /// HypervisorGroup class. /// </summary> /// <param name="model">The HypervisorGroup to reference.</param> private void ReadEntityProperties(HypervisorGroup model) { // Calculated properties. this.AcceptingNewBuilds = !model.TagsMetas.Any(x => x.Tag.Name == "no new builds"); this.CapacityConstraint = FormatHelper.CapacityConstraintBitsToString(model.CapacityConstraintBits); this.CapacityConstraintBits = model.CapacityConstraintBits; // IHasCapacity members. this.TotalCapacity = model.TotalCapacity; this.UsedCapacity = model.UsedCapacity; // Per Justin - anything over 100% just display as 100%. this.UsedCapacityPercent = Math.Min(1, model.UsedCapacityPercent); }
/// <summary> /// Initializes a new instance of the /// <see cref="HypervisorGroupListIndexViewModel"/> class. /// </summary> /// <param name="model">The HypervisorGroup to reference.</param> public HypervisorGroupListIndexViewModel(HypervisorGroup model) : base(model) { // Properties from the entity, notes and tags. this.ReadEntityProperties(model); // Related entities. this.VirtualMachineCount = model.Hypervisors .Where(x => !x.Inactive) .Sum(x => x.VirtualMachines .Where(y => !y.Inactive) .Count()); this.HypervisorCount = model.Hypervisors .Where(x => !x.Inactive) .Count(); }
/// <summary> /// Initializes a new instance of the /// <see cref="HypervisorGroupListCapacityViewModel"/> class. /// </summary> /// <param name="model">The HypervisorGroup to reference.</param> public HypervisorGroupListCapacityViewModel(HypervisorGroup model) : base(model) { this.ReadEntityProperties(model); if (model.Inactive) { this.ActiveVirtualMachineCount = 0; } else { this.ActiveVirtualMachineCount = model.Hypervisors .Where(x => !x.Inactive) .SelectMany(x => x.VirtualMachines) .Where(x => !x.Inactive) .Count(); } }
public ActionResult Edit(HypervisorGroup hypervisorgroup) { if (ModelState.IsValid) { hypervisorgroup.LastUpdated = DateTime.Now; if (hypervisorgroup.HighAvailabilityCalculationType != 1) { hypervisorgroup.HighAvailabilityReservedHypervisors = 0; } if (hypervisorgroup.HighAvailabilityCalculationType != 2) { hypervisorgroup.HighAvailabilityReservedPercentage = 0; } if (hypervisorgroup.Inactive) { if (hypervisorgroup.InactiveDate == null) { hypervisorgroup.InactiveDate = hypervisorgroup.LastUpdated; } } else { if (hypervisorgroup.InactiveDate != null) { hypervisorgroup.InactiveDate = null; } } this.db.HypervisorGroups.Attach(hypervisorgroup); this.db.ObjectStateManager.ChangeObjectState(hypervisorgroup, EntityState.Modified); this.db.SaveChanges(); return(this.RedirectToAction("Details", new { id = hypervisorgroup.Id })); } ViewBag.HypervisorGroupType_Id_Select = new SelectList(this.db.HypervisorGroupTypes.OrderBy(x => x.Name), "Id", "Name", hypervisorgroup.HypervisorGroupType_Id); return(this.View(hypervisorgroup)); }
/// <summary> /// Populates properties on the view model from an instance of the /// HypervisorGroup class. /// </summary> /// <param name="model">The HypervisorGroup to reference.</param> private void ReadEntityProperties(HypervisorGroup model) { // Properties from the entity. this.CreatedDate = model.CreatedDate; this.LastUpdated = model.LastUpdated; this.InactiveDate = model.InactiveDate; this.HighAvailabilityCalculationType = model.HighAvailabilityCalculationType; this.HighAvailabilityReservedHypervisors = model.HighAvailabilityReservedHypervisors; this.HighAvailabilityReservedPercentage = model.HighAvailabilityReservedPercentage; // IHasCapacity Members. this.TotalCapacity = model.TotalCapacity; this.UsedCapacity = model.UsedCapacity; this.UsedCapacityPercent = model.UsedCapacityPercent; // Calculated properties. this.ComputeCapacity = model.ComputeCapacity; this.MemoryCapacity = model.MemoryCapacity; this.StorageCapacity = model.StorageCapacity; this.MaximumCapacity = model.MaximumCapacity; // Related entities. this.HypervisorGroupType = model.HypervisorGroupType; this.CapacityRules = CapacityRuleListCalculationViewModel.SelectMany(model.CapacityRulesMetas, model); // Notes and Tags. this.Notes = model.Notes .OrderByDescending(x => x.CreatedAt) .AsEnumerable() .Select(x => new NoteDetailsViewModel(x)) .ToList(); this.Tags = model.TagsMetas .OrderBy(x => x.Tag.Name) .AsEnumerable() .Select(x => new TagDetailsViewModel(x)) .ToList(); }
/// <summary> /// Initializes a new instance of the /// <see cref="HypervisorGroupListNutanixViewModel"/> class. /// </summary> /// <param name="model">The HypervisorGroup to reference.</param> public HypervisorGroupListNutanixViewModel(HypervisorGroup model) : base(model) { // Properties from the entity. this.ReadEntityProperties(model); // Related entities. this.ActiveVirtualMachineCount = model.Hypervisors .Where(x => !x.Inactive) .SelectMany(x => x.VirtualMachines) .Where(x => !x.Inactive) .Count(); List <MachineTypeAndCountViewModel> virtualMachines = model.Hypervisors .Where(x => !x.Inactive) .SelectMany(x => x.VirtualMachines) .Where(x => !x.Inactive) .SelectMany(x => x.XenDesktopBrokerDesktops) .Where(x => !x.Inactive) .GroupBy(x => x.Id) .Select(x => x.FirstOrDefault()) .GroupBy(x => x.XenDesktopCatalog.XenDesktopCatalogType) .Select(x => new MachineTypeAndCountViewModel { Name = x.Key.Name, Count = x.Count() }) .ToList(); int remainder = this.ActiveVirtualMachineCount - virtualMachines.Sum(x => x.Count); if (remainder > 0) { virtualMachines.Add(new MachineTypeAndCountViewModel { Name = "Infrastructure", Count = remainder }); } this.VirtualMachines = virtualMachines; }
/// <summary> /// Initializes a new instance of the /// <see cref="HypervisorGroupReferenceViewModel" /> class. /// </summary> /// <param name="model">The HypervisorGroup to reference.</param> public HypervisorGroupReferenceViewModel(HypervisorGroup model) { this.Id = model.Id; this.Name = model.Name; this.Inactive = model.Inactive; }