public IHttpActionResult Get(int id, int?businessCategoryId = null) { try { Repository.Entities.Business business = null; if (businessCategoryId == null) { business = _repository.GetBusiness(id); } else { var categoryBusinesses = _repository.GetBusinesses((int)businessCategoryId); // if the category doesn't exist, we should't try to get the businesses if (categoryBusinesses != null) { business = categoryBusinesses.FirstOrDefault(bc => bc.id == id); } } if (business != null) { var returnValue = _businessFactory.CreateBusiness(business); return(Ok(returnValue)); } else { return(NotFound()); } } catch (Exception) { return(InternalServerError()); } }