Beispiel #1
0
    /// <summary>
    /// Cria os alunos de uma determinada turma atraves do retorno da API
    /// </summary>
    /// <param name="alunosResponse"></param>
    public void SaveStudents(AlunosResponse alunosResponse)
    {
        DatabaseAcess databaseAcess = new DatabaseAcess();

        databaseAcess.TryCreateTable("Student", "SchoolID INTEGER, ClassID INTEGER, StudentID PRIMARY KEY NOT NULL, StudentName VARCHAR(255) NOT NULL, FOREIGN KEY (SchoolID) REFERENCES Escola(SchoolID), FOREIGN KEY (ClassID) REFERENCES Class(ClassID)");

        foreach (Aluno aluno in alunosResponse.retorno)
        {
            databaseAcess.TryInsertIntoTable("Student", $"SchoolID, ClassID, StudentID, StudentName", $"{1}, {alunosResponse.turmaId}, {aluno.id}, '{aluno.nome}'");
        }

        databaseAcess.Close();

        onLoadStudents?.Invoke(alunosResponse.retorno);
    }
Beispiel #2
0
    /// <summary>
    /// Retorna uma lista de Alunos de uma Turma especificada pelo parametro turmaId
    /// </summary>
    /// <param name="turmaId">Número da turma</param>
    /// <param name="onSucess">Callback de sucesso</param>
    /// <param name="onError">Callback de erro</param>
    public void GetAlunos(int turmaId, Action <AlunosResponse> onSucess = null, Action <Exception> onError = null)
    {
        RestClient.Post(basePath + "/listar/alunos/turma", new TurmaRequest {
            turmaId = turmaId
        }).Then(proxy =>
        {
            AlunosResponse response = JsonUtility.FromJson <AlunosResponse>(proxy.Text);

            response.turmaId = turmaId;

            LogMessage("Response", JsonUtility.ToJson(response, true));

            onSucess.Invoke(response);
        }).Catch(err => {
            LogMessage("Error", err.Message);

            onError.Invoke(err);
        });
    }