Example #1
0
        public bool ToggleProxyReservation(int computerId, bool enable)
        {
            var computerServices = new ComputerServices();
            var computer         = computerServices.GetComputer(computerId);

            computer.ProxyReservation = Convert.ToInt16(enable);
            computerServices.UpdateComputer(computer);
            return(true);
        }
        public ActionResultDTO DeleteProfile(int profileId)
        {
            var profile = ReadProfile(profileId);

            if (profile == null)
            {
                return new ActionResultDTO {
                           ErrorMessage = "Image Profile Was Not Found", Id = 0
                }
            }
            ;
            _uow.ImageProfileRepository.Delete(profileId);

            _uow.Save();
            var computers       = _uow.ComputerRepository.Get(x => x.ImageProfileId == profileId);
            var computerService = new ComputerServices();

            foreach (var computer in computers)
            {
                computer.ImageProfileId = -1;

                computerService.UpdateComputer(computer);
            }

            var groups       = _uow.GroupRepository.Get(x => x.ImageProfileId == profileId);
            var groupService = new GroupServices();

            foreach (var group in groups)
            {
                group.ImageProfileId = -1;
                groupService.UpdateGroup(group);
            }

            var groupProperties      = _uow.GroupPropertyRepository.Get(x => x.ImageProfileId == profileId);
            var groupPropertyService = new GroupPropertyServices();

            foreach (var groupProperty in groupProperties)
            {
                groupProperty.ImageProfileId = -1;
                groupPropertyService.UpdateGroupProperty(groupProperty);
            }

            var actionResult = new ActionResultDTO();

            actionResult.Success = true;
            actionResult.Id      = profile.Id;

            return(actionResult);
        }
Example #3
0
        public bool ToggleComputerBootMenu(int computerId, bool enable)
        {
            var computerServices = new ComputerServices();
            var computer         = computerServices.GetComputer(computerId);

            computer.CustomBootEnabled = Convert.ToInt16(enable);
            computerServices.UpdateComputer(computer);

            if (enable)
            {
                CreateBootFiles(computer.Id);
            }

            return(true);
        }
Example #4
0
        public ActionResultDTO DeleteRoom(int roomId)
        {
            var room = GetRoom(roomId);

            if (room == null)
            {
                return new ActionResultDTO {
                           ErrorMessage = "Room Not Found", Id = 0
                }
            }
            ;
            _uow.RoomRepository.Delete(roomId);
            _uow.Save();

            var computers       = _uow.ComputerRepository.Get(x => x.RoomId == roomId);
            var computerService = new ComputerServices();

            foreach (var computer in computers)
            {
                computer.RoomId = -1;

                computerService.UpdateComputer(computer);
            }

            var groupProperties      = _uow.GroupPropertyRepository.Get(x => x.RoomId == roomId);
            var groupPropertyService = new GroupPropertyServices();

            foreach (var groupProperty in groupProperties)
            {
                groupProperty.RoomId = -1;
                groupPropertyService.UpdateGroupProperty(groupProperty);
            }

            var actionResult = new ActionResultDTO();

            actionResult.Success = true;
            actionResult.Id      = room.Id;
            return(actionResult);
        }
Example #5
0
        public ActionResultDTO DeleteBuilding(int buildingId)
        {
            var actionResult = new ActionResultDTO();
            var building     = GetBuilding(buildingId);

            if (building == null)
            {
                return new ActionResultDTO {
                           ErrorMessage = "Building Not Found", Id = 0
                }
            }
            ;

            _uow.BuildingRepository.Delete(buildingId);
            _uow.Save();

            var computers       = _uow.ComputerRepository.Get(x => x.BuildingId == buildingId);
            var computerService = new ComputerServices();

            foreach (var computer in computers)
            {
                computer.BuildingId = -1;

                computerService.UpdateComputer(computer);
            }

            var groupProperties      = _uow.GroupPropertyRepository.Get(x => x.BuildingId == buildingId);
            var groupPropertyService = new GroupPropertyServices();

            foreach (var groupProperty in groupProperties)
            {
                groupProperty.BuildingId = -1;
                groupPropertyService.UpdateGroupProperty(groupProperty);
            }
            actionResult.Success = true;
            actionResult.Id      = buildingId;

            return(actionResult);
        }
Example #6
0
        public ActionResultDTO DeleteSite(int siteId)
        {
            var site = GetSite(siteId);

            if (site == null)
            {
                return new ActionResultDTO {
                           ErrorMessage = "Site Not Found", Id = 0
                }
            }
            ;
            _uow.SiteRepository.Delete(siteId);
            _uow.Save();

            var computers       = _uow.ComputerRepository.Get(x => x.SiteId == siteId);
            var computerService = new ComputerServices();

            foreach (var computer in computers)
            {
                computer.SiteId = -1;

                computerService.UpdateComputer(computer);
            }

            var groupProperties      = _uow.GroupPropertyRepository.Get(x => x.SiteId == siteId);
            var groupPropertyService = new GroupPropertyServices();

            foreach (var groupProperty in groupProperties)
            {
                groupProperty.SiteId = -1;
                groupPropertyService.UpdateGroupProperty(groupProperty);
            }

            var actionResult = new ActionResultDTO();

            actionResult.Success = true;
            actionResult.Id      = site.Id;
            return(actionResult);
        }
        public ActionResultDTO DeleteAlternateServerIp(int alternateServerIpId)
        {
            var alternateServerIp = GetAlternateServerIp(alternateServerIpId);

            if (alternateServerIp == null)
            {
                return new ActionResultDTO {
                           ErrorMessage = "Alternate Server Ip Not Found", Id = 0
                }
            }
            ;
            _uow.AlternateServerIpRepository.Delete(alternateServerIpId);
            _uow.Save();
            var computers       = _uow.ComputerRepository.Get(x => x.AlternateServerIpId == alternateServerIpId);
            var computerService = new ComputerServices();

            foreach (var computer in computers)
            {
                computer.AlternateServerIpId = -1;

                computerService.UpdateComputer(computer);
            }


            var groupProperties      = _uow.GroupPropertyRepository.Get(x => x.AlternateServerIpId == alternateServerIpId);
            var groupPropertyService = new GroupPropertyServices();

            foreach (var groupProperty in groupProperties)
            {
                groupProperty.AlternateServerIpId = -1;
                groupPropertyService.UpdateGroupProperty(groupProperty);
            }
            var actionResult = new ActionResultDTO();

            actionResult.Success = true;
            actionResult.Id      = alternateServerIp.Id;
            return(actionResult);
        }
        public void UpdateComputerProperties(GroupPropertyEntity groupProperty)
        {
            if (groupProperty == null)
            {
                return;
            }
            var groupImageClassifications = new List <GroupImageClassificationEntity>();

            if (Convert.ToBoolean(groupProperty.ImageClassificationsEnabled))
            {
                groupImageClassifications =
                    new GroupServices().GetGroupImageClassifications(groupProperty.GroupId);
            }
            foreach (var computer in new GroupServices().GetGroupMembersWithImages(groupProperty.GroupId))
            {
                if (Convert.ToBoolean(groupProperty.ImageEnabled))
                {
                    computer.ImageId = groupProperty.ImageId;
                }
                if (Convert.ToBoolean(groupProperty.ImageProfileEnabled))
                {
                    computer.ImageProfileId = groupProperty.ImageProfileId;
                }
                if (Convert.ToBoolean(groupProperty.DescriptionEnabled))
                {
                    computer.Description = groupProperty.Description;
                }
                if (Convert.ToBoolean(groupProperty.SiteEnabled))
                {
                    computer.SiteId = groupProperty.SiteId;
                }
                if (Convert.ToBoolean(groupProperty.BuildingEnabled))
                {
                    computer.BuildingId = groupProperty.BuildingId;
                }
                if (Convert.ToBoolean(groupProperty.RoomEnabled))
                {
                    computer.RoomId = groupProperty.RoomId;
                }
                if (Convert.ToBoolean(groupProperty.CustomAttribute1Enabled))
                {
                    computer.CustomAttribute1 = groupProperty.CustomAttribute1;
                }
                if (Convert.ToBoolean(groupProperty.CustomAttribute2Enabled))
                {
                    computer.CustomAttribute2 = groupProperty.CustomAttribute2;
                }
                if (Convert.ToBoolean(groupProperty.CustomAttribute3Enabled))
                {
                    computer.CustomAttribute3 = groupProperty.CustomAttribute3;
                }
                if (Convert.ToBoolean(groupProperty.CustomAttribute4Enabled))
                {
                    computer.CustomAttribute4 = groupProperty.CustomAttribute4;
                }
                if (Convert.ToBoolean(groupProperty.CustomAttribute5Enabled))
                {
                    computer.CustomAttribute5 = groupProperty.CustomAttribute5;
                }
                if (Convert.ToBoolean(groupProperty.ProxyEnabledEnabled))
                {
                    computer.ProxyReservation = groupProperty.ProxyEnabled;
                }
                if (Convert.ToBoolean(groupProperty.ClusterGroupEnabled))
                {
                    computer.ClusterGroupId = groupProperty.ClusterGroupId;
                }
                if (Convert.ToBoolean(groupProperty.AlternateServerIpEnabled))
                {
                    computer.AlternateServerIpId = groupProperty.AlternateServerIpId;
                }
                if (Convert.ToBoolean(groupProperty.ImageClassificationsEnabled))
                {
                    var computerImageClassifications = new List <ComputerImageClassificationEntity>();
                    if (new ComputerServices().DeleteComputerImageClassifications(computer.Id))
                    {
                        foreach (var imageClass in groupImageClassifications)
                        {
                            computerImageClassifications.Add(
                                new ComputerImageClassificationEntity
                            {
                                ComputerId            = computer.Id,
                                ImageClassificationId = imageClass.ImageClassificationId
                            });
                        }
                    }
                    new ComputerImageClassificationServices().AddClassifications(computerImageClassifications);
                }

                var computerServices = new ComputerServices();
                computerServices.UpdateComputer(computer);
                if (Convert.ToBoolean(groupProperty.TftpServerEnabled) ||
                    Convert.ToBoolean(groupProperty.BootFileEnabled))
                {
                    var proxyServices = new ComputerProxyReservationServices();
                    var computerProxy = computerServices.GetComputerProxyReservation(computer.Id);
                    if (computerProxy == null)
                    {
                        computerProxy            = new ComputerProxyReservationEntity();
                        computerProxy.ComputerId = computer.Id;
                    }
                    if (Convert.ToBoolean(groupProperty.TftpServerEnabled))
                    {
                        computerProxy.NextServer = groupProperty.TftpServer;
                    }
                    if (Convert.ToBoolean(groupProperty.BootFileEnabled))
                    {
                        computerProxy.BootFile = groupProperty.BootFile;
                    }
                    proxyServices.UpdateComputerProxyReservation(computerProxy);
                }
            }
        }
Example #9
0
        public ActionResultDTO DeleteImage(int imageId)
        {
            var image = GetImage(imageId);

            if (image == null)
            {
                return new ActionResultDTO {
                           ErrorMessage = "Image Not Found", Id = 0
                }
            }
            ;
            var result = new ActionResultDTO();

            if (Convert.ToBoolean(image.Protected))
            {
                result.ErrorMessage = "This Image Is Protected And Cannot Be Deleted";

                return(result);
            }

            _uow.ImageRepository.Delete(image.Id);
            _uow.Save();
            result.Id = imageId;
            //Check if image name is empty or null, return if so or something will be deleted that shouldn't be
            if (string.IsNullOrEmpty(image.Name))
            {
                return(result);
            }

            var computers       = _uow.ComputerRepository.Get(x => x.ImageId == imageId);
            var computerService = new ComputerServices();

            foreach (var computer in computers)
            {
                computer.ImageId        = -1;
                computer.ImageProfileId = -1;
                computerService.UpdateComputer(computer);
            }

            var groups       = _uow.GroupRepository.Get(x => x.ImageId == imageId);
            var groupService = new GroupServices();

            foreach (var group in groups)
            {
                group.ImageId        = -1;
                group.ImageProfileId = -1;
                groupService.UpdateGroup(group);
            }

            var groupProperties      = _uow.GroupPropertyRepository.Get(x => x.ImageId == imageId);
            var groupPropertyService = new GroupPropertyServices();

            foreach (var groupProperty in groupProperties)
            {
                groupProperty.ImageId        = -1;
                groupProperty.ImageProfileId = -1;
                groupPropertyService.UpdateGroupProperty(groupProperty);
            }

            var delDirectoryResult = new FilesystemServices().DeleteImageFolders(image.Name);

            result.Success = delDirectoryResult;

            return(result);
        }
Example #10
0
        public ActionResultDTO DeleteClusterGroup(int clusterGroupId)
        {
            var clusterGroup = GetClusterGroup(clusterGroupId);

            if (clusterGroup == null)
            {
                return new ActionResultDTO {
                           ErrorMessage = "Cluster Group Not Found", Id = 0
                }
            }
            ;
            _uow.ClusterGroupRepository.Delete(clusterGroupId);
            _uow.Save();

            var sites       = _uow.SiteRepository.Get(x => x.ClusterGroupId == clusterGroupId);
            var siteService = new SiteServices();

            foreach (var site in sites)
            {
                site.ClusterGroupId = -1;

                siteService.UpdateSite(site);
            }

            var buildings       = _uow.BuildingRepository.Get(x => x.ClusterGroupId == clusterGroupId);
            var buildingService = new BuildingServices();

            foreach (var building in buildings)
            {
                building.ClusterGroupId = -1;
                buildingService.UpdateBuilding(building);
            }

            var rooms       = _uow.RoomRepository.Get(x => x.ClusterGroupId == clusterGroupId);
            var roomService = new RoomServices();

            foreach (var room in rooms)
            {
                room.ClusterGroupId = -1;
                roomService.UpdateRoom(room);
            }

            var computers       = _uow.ComputerRepository.Get(x => x.ClusterGroupId == clusterGroupId);
            var computerService = new ComputerServices();

            foreach (var computer in computers)
            {
                computer.ClusterGroupId = -1;
                computerService.UpdateComputer(computer);
            }

            var groups       = _uow.GroupRepository.Get(x => x.ClusterGroupId == clusterGroupId);
            var groupService = new GroupServices();

            foreach (var group in groups)
            {
                group.ClusterGroupId = -1;
                groupService.UpdateGroup(group);
            }

            var groupProperties      = _uow.GroupPropertyRepository.Get(x => x.ClusterGroupId == clusterGroupId);
            var groupPropertyService = new GroupPropertyServices();

            foreach (var groupProperty in groupProperties)
            {
                groupProperty.ClusterGroupId = -1;
                groupPropertyService.UpdateGroupProperty(groupProperty);
            }

            var actionResult = new ActionResultDTO();

            actionResult.Success = true;
            actionResult.Id      = clusterGroup.Id;
            return(actionResult);
        }