Q:

How to get by Id from a repository Class .NET Core MVC

I have a repository.cs file like this:
private static List<AdminResponse> responses = new List<AdminResponse>();

public static IEnumerable<AdminResponse> Responses => responses;

public static void AddResponse(AdminResponse response)
{
    responses.Add(response);
}

I am trying to retrieve an employee for editing from Employeescontroller.cs. The employee model has int Id as key.
What should I write inside:
public ActionResult Details(int? id)
{
     // What code goes here I cannot figure out :(
     return View();
}

Thank you.

A:

To lookup the item you want to display, you can use the Linq method FirstOrDefault, like this:
var response = responses.FirstOrDefault(r => r.Id == id);

As your method's input variable id is nullable (the type is int?) you may have to use id.Value in the above line.
Before to start searching, you may want to check if that id is not empty, and return HttpNotFound() or something like that.

