/// <summary>
        /// Initializes a new instance of the
        /// <see cref="DataStoreGroupDetailsViewModel"/> class.
        /// </summary>
        /// <param name="model">The DataStoreGroup to reference.</param>
        public DataStoreGroupDetailsViewModel(DataStoreGroup model)
            : base(model)
        {
            // Properties from the entity, notes and tags.
            this.ReadEntityProperties(model);

            // Related entities.
            this.ActiveDataStoreCount = model.DataStores
                                        .Where(x => !x.Inactive)
                                        .Count();

            this.TotalDataStoreCount = model.DataStores.Count();

            this.ActiveVirtualMachineCount = model.DataStores
                                             .Where(x => !x.Inactive)
                                             .SelectMany(x => x.VirtualHardDrives)
                                             .GroupBy(x => x.Id)
                                             .Select(x => x.FirstOrDefault())
                                             .Where(x => !x.Inactive)
                                             .SelectMany(x => x.VirtualMachines)
                                             .GroupBy(x => x.Id)
                                             .Select(x => x.FirstOrDefault())
                                             .Where(x => !x.Inactive)
                                             .Count();

            this.TotalVirtualMachineCount = model.DataStores
                                            .SelectMany(x => x.VirtualHardDrives)
                                            .GroupBy(x => x.Id)
                                            .Select(x => x.FirstOrDefault())
                                            .SelectMany(x => x.VirtualMachines)
                                            .GroupBy(x => x.Id)
                                            .Select(x => x.FirstOrDefault())
                                            .Count();
        }
        public ActionResult Edit(DataStoreGroup datastoregroup)
        {
            if (ModelState.IsValid)
            {
                datastoregroup.LastUpdated = DateTime.Now;

                if (datastoregroup.Inactive)
                {
                    if (datastoregroup.InactiveDate == null)
                    {
                        datastoregroup.InactiveDate = datastoregroup.LastUpdated;
                    }
                }
                else
                {
                    if (datastoregroup.InactiveDate != null)
                    {
                        datastoregroup.InactiveDate = null;
                    }
                }

                this.db.DataStoreGroups.Attach(datastoregroup);
                this.db.ObjectStateManager.ChangeObjectState(datastoregroup, EntityState.Modified);
                this.db.SaveChanges();
                return(this.RedirectToAction("Details", new { id = datastoregroup.Id }));
            }

            return(this.View(datastoregroup));
        }
        public ActionResult DeleteConfirmed(Guid id)
        {
            DataStoreGroup datastoregroup = this.db.DataStoreGroups.Single(d => d.Id == id);

            this.db.DataStoreGroups.DeleteObject(datastoregroup);
            this.db.SaveChanges();
            return(this.RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="DataStoreGroupListIndexViewModel"/> class.
        /// </summary>
        /// <param name="model">The DataStoreGroup to reference.</param>
        /// <param name="activeDataStoreCount">The number of active
        /// Virtual Hard Drives related to the DataStoreGroup.</param>
        /// <param name="activeVirtualMachineCount">The number of active
        /// Virtual Machines related to the DataStoreGroup.</param>
        private DataStoreGroupListIndexViewModel(DataStoreGroup model, int activeDataStoreCount, int activeVirtualMachineCount)
            : base(model)
        {
            // Properties from the entity, notes and tags.
            this.ReadEntityProperties(model);

            // Related entities.
            this.ActiveDataStoreCount      = activeDataStoreCount;
            this.ActiveVirtualMachineCount = activeVirtualMachineCount;
        }
        public ActionResult Edit(Guid id)
        {
            DataStoreGroup datastoregroup = this.db.DataStoreGroups.Single(d => d.Id == id);

            if (datastoregroup == null)
            {
                return(this.HttpNotFound());
            }

            return(this.View(datastoregroup));
        }
        public ActionResult Create(DataStoreGroup datastoregroup)
        {
            if (ModelState.IsValid)
            {
                datastoregroup.Id          = Guid.NewGuid();
                datastoregroup.CreatedDate = DateTime.Now;
                datastoregroup.LastUpdated = datastoregroup.CreatedDate;

                this.db.DataStoreGroups.AddObject(datastoregroup);
                this.db.SaveChanges();
                return(this.RedirectToAction("Details", new { id = datastoregroup.Id }));
            }

            return(this.View(datastoregroup));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Populates properties on the view model from an instance of the
        /// DataStoreGroup class.
        /// </summary>
        /// <param name="model">The DataStoreGroup to reference.</param>
        private void ReadEntityProperties(DataStoreGroup model)
        {
            // Properties from the entity.
            this.Id                  = model.Id;
            this.Name                = model.Name;
            this.Inactive            = model.Inactive;
            this.Capacity            = model.Capacity;
            this.FreeSpace           = model.FreeSpace;
            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
        /// DataStoreGroup class.
        /// </summary>
        /// <param name="model">The DataStoreGroup to reference.</param>
        private void ReadEntityProperties(DataStoreGroup model)
        {
            // Properties from the entity.
            this.InactiveDate = model.InactiveDate;
            this.Id           = model.Id;
            this.Name         = model.Name;
            this.CreatedDate  = model.CreatedDate;
            this.LastUpdated  = model.LastUpdated;
            this.Inactive     = model.Inactive;
            this.InactiveDate = model.InactiveDate;
            this.Capacity     = model.Capacity;
            this.FreeSpace    = model.FreeSpace;

            // IHasCapacity Members.
            this.TotalCapacity       = model.TotalCapacity;
            this.UsedCapacity        = model.UsedCapacity;
            this.UsedCapacityPercent = model.UsedCapacityPercent;

            // IStorageCapacity Members.
            this.TotalStorageCapacity       = model.TotalStorageCapacity;
            this.UsedStorageCapacity        = model.UsedStorageCapacity;
            this.UsedStorageCapacityPercent = model.UsedStorageCapacityPercent;

            // 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();
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="DataStoreGroupReferenceViewModel" /> class.
 /// </summary>
 /// <param name="model">The DataStoreGroup to reference.</param>
 public DataStoreGroupReferenceViewModel(DataStoreGroup model)
 {
     this.Id       = model.Id;
     this.Name     = model.Name;
     this.Inactive = model.Inactive;
 }