public async Task <IActionResult> GetCatalog([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var catalog = await catalogRepository.FindById(id); if (catalog == null) { return(NotFound()); } CatalogDTO dto = new CatalogDTO(); dto.CatalogId = catalog.CatalogId; dto.Date = catalog.Date; dto.CatalogDescription = catalog.CatalogDescription; dto.CatalogName = catalog.CatalogName; dto.products = new List <ProductDTO>(); foreach (CatalogProduct cp in catalog.CatalogProducts) { ProductDTO pdto = productToDTO(cp.Product); dto.products.Add(pdto); } return(Ok(dto)); }