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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }