public async Task <Product> CreateProduct(int CategoryId, Product Product) { //if (Product.CategoryId != null && CategoryId != Product.CategoryId) //{ // throw new BadRequestOperationException("URL Category id and Product.CategoryId should be equal"); //} Product.CategoryId = CategoryId; await ValidateCategory(CategoryId); var ProductEntity = mapper.Map <ProductEntity>(Product); // ProductEntity.Category = null; EcomakRepository.CreateProduct(ProductEntity); if (await EcomakRepository.SaveChangesAsync()) { return(mapper.Map <Product>(ProductEntity)); } throw new Exception("there where and error with the DB"); }