Esempio n. 1
0
        public IActionResult OnPost([FromRoute] int productId, [FromRoute] int mealId, [FromForm] decimal Weight)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Meal    = mealData.GetById(mealId);
            Meal    = mealData.LoadIngredients(Meal);
            Product = productData.GetById(productId);

            MealProduct = new MealProduct();
            var modMeal = Meal;

            if (Weight > 0)
            {
                MetaAddIngredientsAndStatistics(productId, mealId, Weight, modMeal);
            }
            else if (Weight == 0)
            {
                MetaRemoveIngredientsAndStatistics(mealId, productId, modMeal);
            }

            mealData.Update(Meal);
            mealData.Commit();

            TempData["Message"] = "Meal saved!";
            return(RedirectToPage("./UpdateMeal", new { mealId = Meal.MealId }));
        }
Esempio n. 2
0
        public IActionResult Post(MealDTO dto)
        {
            try
            {
                Meal = ApiRepository.DtoToMeal(dto);

                mealData.Add(Meal);

                if (mealData.Commit() > 0)
                {
                    return(CreatedAtAction("GetById", new { id = Meal.MealId }, Meal));
                }
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest());
        }
Esempio n. 3
0
        public IActionResult OnPost(int mealId)
        {
            Meal = mealData.Delete(mealId);
            mealData.Commit();

            if (Meal != null)
            {
                return(RedirectToPage("./MealList"));
            }

            TempData["Message"] = $"{Meal.Name} deleted!";
            return(RedirectToPage("./MealList"));
        }
Esempio n. 4
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            if (Meal.MealId > 0)
            {
                mealData.Update(Meal);
            }
            else
            {
                mealData.Add(Meal);

                Meal.ImgPath = "groceries.png";
                Meal.Owner   = User.Identity.Name;
            }

            mealData.Commit();

            TempData["Message"] = "Meal saved!";

            return(RedirectToPage("./Details", new { mealId = Meal.MealId }));
        }