ApplicationUser List in MVC 5 is empty?

11 Views Asked by At

I'm trying to create a List of the ApplicationUsers to find the customer that corresponds to the correct Invoice. I tried the following below, but got a NullReferenceException:

System.NullReferenceException: Object reference not set to an instance of an object.

The code in my Controller:

private string FindCustomerForReservation(List<Invoice> invoices, List<ApplicationUser> customers, Reservation currentReservation)
    {
        string customername;

        Invoice correspInvoice = invoices.Find(f => f.Id == currentReservation.Invoicenumber);

        ApplicationUser customer =  customers.Find(k => k.Id == correspInvoice.CustomerId);

        customername = customer.UserName;

        return customername;
    }

So I assume the list is null or empty. Is that correct or is it something else?

How would I fix this?

0

There are 0 best solutions below