public IActionResult Post(MealProductDTO dto) { try { MealProduct = ApiRepository.DtoToMealProduct(dto); var exists = mealProductData.GetByIds(MealProduct.MealId, MealProduct.ProductId); if (exists != null) { return(BadRequest("Cannot add, entity already exists!")); } mealProductData.SetValues(MealProduct, dto.MealId, dto.ProductId, dto.ProductWeight); mealProductData.Add(MealProduct); if (mealProductData.Commit() > 0) { return(CreatedAtAction("GetById", new { mid = MealProduct.MealId, pid = MealProduct.ProductId }, MealProduct)); } } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } return(BadRequest()); }
private void MetaAddIngredientsAndStatistics(int productId, int mealId, decimal Weight, Meal modMeal) { Meal = mealData.Recomposite(modMeal, Product, Weight); if (Meal.MealProducts != null) { MealProducts = Meal.MealProducts.ToList(); } MealProduct = mealProductData.SetValues(MealProduct, mealId, productId, Weight); mealProductData.Add(MealProduct); MealProducts.Add(MealProduct); Meal.Products = Products; Meal.MealProducts = MealProducts; mealData.Commit(); }