Example #1
0
        public IActionResult FoodSelect(HomeSelectViewModel model, string submit)
        {
            if (ModelState.IsValid)
            {
                var pm = DiabetCalcService.EnsureMemberExists(_diabetWebData, User.Identity.Name);
                if ((model.SelectedItemIds == null) || (model.SelectedItemIds.Length == 0))
                {
                    return(RedirectToAction(nameof(FoodSelect)));
                }


                /// Clear Add
                /// Update and Calculate
                /// Set Favorites
                if ("Set Favorites".Equals(submit))
                {
                    //set favorites on the selected list
                    var fooditems    = _diabetWebData.GetSelectItems(model.SelectedItemIds.ToArray <int>());
                    var updateditems = fooditems.Select(fi => { fi.Favorites = model.SetFavorite; return(fi); }).ToArray <FoodItem>();
                    _diabetWebData.UpdateFoodItems(updateditems);
                    return(RedirectToAction(nameof(FoodSelect)));
                }
                else
                {
                    //if clear add - remove existing
                    if ("Remove/Add and Calc".Equals(submit))
                    {
                        var temp = _diabetWebData.GetMealItems(User.Identity.Name);
                        if ((temp != null) && (temp.Length > 0))
                        {
                            _diabetWebData.DeleteMealItems(temp);
                        }
                    }

                    // update meal by adding more items
                    var fooditems = _diabetWebData.GetSelectItems(model.SelectedItemIds.ToArray <int>());
                    var meals     = new List <MealItem>();
                    foreach (var fooditem in fooditems)
                    {
                        var mealitem = new MealItem {
                            MemberItem = pm, FoodItem = fooditem, Weight = 0, DosePart = 0
                        };
                        meals.Add(mealitem);
                    }
                    _diabetWebData.AddMealItems(meals.ToArray <MealItem>());
                    if ("Add and Stay".Equals(submit))
                    {
                        return(RedirectToAction(nameof(FoodSelect)));
                    }
                    else
                    {
                        return(RedirectToAction(nameof(DiabetCalc)));
                    }
                }
            }
            else
            {
                return(View());
            }
        }
Example #2
0
        public IActionResult FoodSelectMod()
        {
            var foods = _diabetWebData.GetSelectItems(null);
            var model = new HomeSelectViewModel {
                FoodItems = foods, GetFavorite = 1
            };

            return(View(model));
        }
Example #3
0
        public IActionResult Select(int?id)
        {
            var student    = _context.Students.Include("StudDiscs").SingleOrDefault(s => s.Id == id);
            var selDiscIds = student.StudDiscs.Select(d => d.DisciplineId);
            var discs      = _context.Disciplines;

            var model = new HomeSelectViewModel {
                Student = student
            };

            model.SelDiscs    = discs.Where(d => selDiscIds.Contains(d.Id)).OrderBy(d => d.Title);
            model.NonSelDiscs = discs.Except(model.SelDiscs).OrderBy(d => d.Title);

            return(View(model));
        }