def updateAClient(commandInPieces): # updates a client that is already in the repository # input - details about the client to be updated (id) and the values that must be edited repoCaller = Repo() listOfClients = repoCaller.getListOfClients() idToUpdate = commandInPieces[1] newId = commandInPieces[2] newName = commandInPieces[3] updatedClient = Client(newId, newName) position = 0 try: validateAClient(updatedClient) for iterator in listOfClients: if Client.getClientId(iterator) == idToUpdate: if commandInPieces[0] != "undo": undoFunction = Undo("updateC", [ "undo", newId, Client.getClientId(iterator), Client.getClientName(iterator), "undo", Client.getClientId(iterator), newId, newName ]) repoCaller.addToListOfOperations(undoFunction) repoCaller.setRedoFalse() repoCaller.removeClientFromPosition(position) repoCaller.insertClientIntoPosition(position, updatedClient) repoCaller.loadIntoFiles() repoCaller.loadIntoPickle() break position += 1 except ClientAlreadyExistsError: print(ClientAlreadyExistsError()) return False
def removeAClient(commandInPieces): # removes a client from the repository # input - details about the client (id) repoCaller = Repo() idToRemove = commandInPieces[1] position = 0 removed = False for iterator in Repo.listOfClients: if Client.getClientId(iterator) == idToRemove: if commandInPieces[0] != "undo": undoFunction = Undo("addC", [ "undo", Client.getClientId(iterator), Client.getClientName(iterator) ]) repoCaller.addToListOfOperations(undoFunction) repoCaller.setRedoFalse() repoCaller.removeClientFromPosition(position) repoCaller.loadIntoFiles() repoCaller.loadIntoPickle() removed = True position += 1 if removed == False: print(IdOfClientDoesntExist()) return False