mardi 1 décembre 2015

Error null validation web api

I ve added some validation and I receive an error which tells me that customers is null and maybe I've entered in an infinite loop.Probably I didn't write the information right.How can I write such that if there are no customers in the database to throw that error?

 public IEnumerable<Customer> GetAllCustomers()
    {
        var customers = GetAllCustomers();
        if (customers == null)
        {
            throw new ValidationException("There are no customers.");
        }
        if (ModelState.IsValid)
        {
            return CustomerRepository.GetAllCustomers();
        }
        else
        {
            throw new ValidationException("Validation error.");
        }

Aucun commentaire:

Enregistrer un commentaire