Esempio n. 1
0
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