public IActionResult UpdateMealPlanRecipe(int id, [FromBody] MealPlanRecipe item) { if (!ModelState.IsValid || item == null || item.id != id) { _logger.LogWarning(LoggingEvents.UpdateItemBadRequest, $"UPDATE({id}) BAD REQUEST"); return(BadRequest()); } var mealPlan = _context.MealPlanRecipes.FirstOrDefault(t => t.id == id); if (mealPlan == null) { _logger.LogWarning(LoggingEvents.UpdateItemNotFound, $"UPDATE(id) NOT FOUND"); return(NotFound()); } try { _context.Database.ExecuteSqlInterpolated( $@"UPDATE MealPlanRecipesView SET meal_plan_name = {item.mealPlanName}, name = {item.name}, count = {item.count} WHERE id = {item.id}; "); } catch (Exception ex) { _logger.LogError(LoggingEvents.UpdateItemApplicationError, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(NoContent()); }
public static MealPlanV2 ToV2(this MealPlan plan) { var length = plan.RecipeIds.Length; var recipes = new MealPlanRecipe[length]; for (int i = 0; i < length; i++) { recipes[i] = new(plan.RecipeIds[i], MealPlanRecipeStatus.Confirmed); } return(new(plan.Date, recipes)); }
public IActionResult InsertMealPlanRecipe([FromBody] MealPlanRecipe item) { if (!ModelState.IsValid) { _logger.LogWarning(LoggingEvents.InsertItemBadRequest, $"Insert BAD REQUEST"); return(BadRequest()); } try { _context.Database.ExecuteSqlInterpolated( $@"INSERT INTO MealPlanRecipesView(meal_plan_name, name, count) VALUES ({item.mealPlanName}, {item.name}, {item.count}); "); } catch (Exception ex) { _logger.LogWarning(LoggingEvents.InsertItemApplicationError, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(NoContent()); }