public async Task <IActionResult> AddProduct([FromRoute] int id, [FromRoute] int idp) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var collection = await collectionRepository.AddCollectionProduct(id, idp); if (collection == null) { return(BadRequest()); } CollectionDTO dto = new CollectionDTO(); dto.CollectionId = collection.CollectionId; dto.collectionName = collection.collectionName; dto.aestheticParameter = collection.aestheticParameter; dto.products = new List <ProductDTO>(); foreach (CollectionProduct cp in collection.CollectionProducts) { ProductDTO pdto = productToDTO(cp.Product); dto.products.Add(pdto); } return(Ok(dto)); }