public DtoActionResult Delete(int imageId) { var u = GetImage(imageId); if (u == null) { return new DtoActionResult { ErrorMessage = "Image Not Found", Id = 0 } } ; if (u.Protected) { return(new DtoActionResult { ErrorMessage = "This Image Is Protected And Cannot Be Deleted", Id = u.Id }); } _uow.ImageRepository.Delete(imageId); _uow.Save(); var actionResult = new DtoActionResult(); actionResult.Success = true; actionResult.Id = u.Id; //Check if image name is empty or null, return if so or something will be deleted that shouldn't be if (string.IsNullOrEmpty(u.Name)) { return(actionResult); } var computers = _uow.ComputerRepository.Get(x => x.ImageId == imageId); var computerService = new ServiceComputer(); 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 ServiceGroup(); foreach (var group in groups) { group.ImageId = -1; group.ImageProfileId = -1; groupService.UpdateGroup(group); } var delDirectoryResult = new FilesystemServices().DeleteImageFolders(u.Name); return(actionResult); }
public DtoActionResult Delete(int imageProfileId) { var u = GetImageProfile(imageProfileId); if (u == null) { return new DtoActionResult { ErrorMessage = "ImageProfile Not Found", Id = 0 } } ; _uow.ImageProfileRepository.Delete(imageProfileId); _uow.Save(); var computers = _uow.ComputerRepository.Get(x => x.ImageProfileId == imageProfileId); var computerService = new ServiceComputer(); foreach (var computer in computers) { computer.ImageProfileId = -1; computerService.UpdateComputer(computer); } var groups = _uow.GroupRepository.Get(x => x.ImageProfileId == imageProfileId); var groupService = new ServiceGroup(); foreach (var group in groups) { group.ImageProfileId = -1; groupService.UpdateGroup(group); } var actionResult = new DtoActionResult(); actionResult.Success = true; actionResult.Id = u.Id; return(actionResult); }