public async Task <FoodResponseObject> CreateOneAsync(CreateFoodDto t) { var foodGroup = await _foodGroupRepository.FindOneByIdAsync(t.FoodGroupId); if (foodGroup == null) { throw new HttpResponseException(HttpStatusCode.NotFound, "FoodGroup not found"); } var found = await _foodRepository.FindOneByNameAsync(t.Name); if (found != null) { throw new HttpResponseException(HttpStatusCode.NotFound, $"Food with name {t.Name} already exists"); } var newFood = new Food { Name = t.Name, FoodGroupId = foodGroup.Id }; await _foodRepository.CreateOneAsync(newFood); return(FoodResponseObject.FromEntity(newFood)); }