예제 #1
0
        public IActionResult OnGet(int productId, int?mealId, bool trigger = false)
        {
            Trigger = trigger;

            if (!mealId.HasValue)
            {
                return(RedirectToPage("./NotFound"));
            }

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

            return(Page());
        }
예제 #2
0
        public IActionResult GetById(int id)
        {
            try
            {
                Meal = mealData.GetById(id);

                if (Meal == null)
                {
                    return(NotFound());
                }

                return(Ok(ApiRepository.MealtoDto(Meal)));
            }

            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }
        }
예제 #3
0
        public IActionResult OnGet(int mealId)
        {
            Meal = mealData.GetById(mealId);
            Meal = mealData.LoadIngredients(Meal);

            if (Meal == null)
            {
                return(RedirectToPage("/NotFound"));
            }
            return(Page());
        }
예제 #4
0
        public IActionResult OnGet(int mealId)
        {
            Meal = mealData.GetById(mealId);
            Meal = mealData.LoadIngredients(Meal);

            Ingredients = Meal.Products.ToList();

            if (Meal.MealProducts != null)
            {
                Stats = Meal.MealProducts.ToList();
            }
            Statistics = mealData.GetStatistics(mealId);

            return(Page());
        }
예제 #5
0
        public IActionResult OnPostProcessMeal(int mealId, [FromRoute] int dayId, [FromRoute] int category, [FromRoute] bool?isremoved = false)
        {
            IsRemoved = isremoved.Value;

            Meal = mealData.GetById(mealId);
            Day  = dayData.GetById(dayId) ?? new Day {
                DayMeals = new List <DayMeal>()
            };

            if (!IsRemoved)
            {
                DayMeal = dayMealData.SetValues(Day, Meal, (MealCategory)category);

                Day.DayMeals.Add(DayMeal);

                if (Day.DayId == 0)
                {
                    Day.OwnerName = User.Identity.Name;
                    Day.Date      = DateTime.Now.Date;
                    dayData.Add(Day);
                }
                else
                {
                    Day = dayData.GetById(dayId);
                    dayData.Update(Day);
                }

                TempData["Message"] = $"{Meal.Name} added to {(MealCategory)category}";
            }
            else
            {
                DayMeal = dayMealData.GetByValues(dayId, mealId, (MealCategory)category);

                Day.DayMeals.Remove(DayMeal);

                TempData["Message"] = $"{Meal.Name} removed from {(MealCategory)category}";
            }

            dayData.Commit();



            return(RedirectToPage("./Today", new { dayId = Day.DayId }));
        }
예제 #6
0
        public IActionResult OnGet(int?mealId)
        {
            if (mealId.HasValue)
            {
                Meal = mealData.GetById(mealId.Value);
            }
            else
            {
                Meal = new Meal();
            }
            if (Meal == null)
            {
                return(RedirectToPage("./NotFound"));
            }

            Products = productData.GetAll();

            return(Page());
        }