how does the AddResponse method work?

0

Good afternoon everyone I am learning ASP.NET Core 2.0 And get to a section where you create a class to use as a repository "Repositorium.AddResponse (Received Object)"

1-) What role does the repositories have for what they do?

2-) What function does the "AddRespose" () method do for it?

to be added to the Startup file in the "ConfigureServices" section

Please explain it in a simpler way, I have read the documentation and I still do not understand

public static class Repository
{
    private static List<Estudiante> responses = new List<Estudiante>();
    public static IEnumerable<Estudiante> Responses
    {
        get
        {
            return responses;
        }
    }
    public static void AddResponse(Estudiante estudiante)
    {
        responses.Add(estudiante);
    }
}

}

    
asked by Maria Perez 11.05.2018 в 18:05
source

1 answer

1

Repositories are the means by which you are going to obtain / insert information, it can be, as in your example, a List<T> defined in the program, as well as the logic of connection to a database, from which you would obtain, modify and insert information

I'll explain, in the code

public static void AddResponse(Estudiante estudiante)
{
     responses.Add(estudiante);
}

What you are doing is adding the student that you receive as a parameter to the list List<Estudiante> that you declare above.

and in the method

public static IEnumerable<Estudiante> Responses
{
    get
    {
        return responses;
    }
}

What you are doing is returning the same list that I mentioned above, that way, you could for example, receive it in a view, to show the information of all your students in a table

Anything that you do not understand what I'm saying, do not hesitate to ask in the comments

    
answered by 11.05.2018 / 18:22
source