public IActionResult Remove(int[] nutritionPlanIds) { //TODO: Remove foods from list foreach (int nutritionPlanId in nutritionPlanIds) { NutritionPlan thePlan = context.NutritionPlans.Single(n => n.ID == nutritionPlanId); context.NutritionPlans.Remove(thePlan); } context.SaveChanges(); return(Redirect("/NutritionPlan")); }
public async Task <IActionResult> ViewNewCustomer(NutritionPlan newPlan) { Notification notification = new Notification(); Customer current = _context.Customers.Where(c => c.CustomerId == newPlan.CustomerId).SingleOrDefault(); notification.Id = current.IdentityUserId; notification.notificationInfo = "Your customized nutritrion plan is now completed"; notification.controllerAction = "CustomerNutritionPlan"; _context.Notifications.Add(notification); _context.NutritionPlans.Add(newPlan); _context.SaveChanges(); return(RedirectToAction("ViewCustomer", new { customerId = newPlan.CustomerId })); }
public IActionResult NutritionPlan(int id) { /*if (id == 0) * { * return Redirect("/NutritionPlan"); * } */ NutritionPlan theNutritionPlan = context.NutritionPlans .Include(plan => plan.Foods) .Single(plan => plan.ID == id); ViewBag.title = "Foods in " + theNutritionPlan.Name; return(View("Index", theNutritionPlan.Foods)); }
public async Task <IActionResult> ViewCustomer(int customerId) { ViewBag.CustomerId = customerId; Customer currentCustomer = _context.Customers.Where(c => c.CustomerId == customerId).SingleOrDefault(); NutritionPlan currentPlan = _context.NutritionPlans.Where(n => n.CustomerId == customerId).SingleOrDefault(); ViewBag.Customer = currentCustomer; List <CustomerMeasurements> customerMeasurements = _context.CustomerMeasurementss.Where(m => m.IdentityUserId == currentCustomer.IdentityUserId).ToList(); List <CustomerMeasurements> sortedMeasurements = customerMeasurements.OrderByDescending(x => x.uploadDate).ToList(); int weightDifference = sortedMeasurements.First().GoalWeight - sortedMeasurements.First().StartingWeight; int weightProgress = sortedMeasurements.First().CurrentWeight - sortedMeasurements.First().StartingWeight; double progressBarPercentage = (double)weightProgress / (double)weightDifference * 100.0; ViewBag.Measurements = sortedMeasurements; ViewBag.progress = progressBarPercentage; return(View(currentPlan)); }
public IActionResult Add(AddNutritionPlanViewModel addNutritionPlanViewModel) { if (ModelState.IsValid) { NutritionPlan newNutritionPlan = new NutritionPlan { Name = addNutritionPlanViewModel.Name, Description = addNutritionPlanViewModel.Description }; context.NutritionPlans.Add(newNutritionPlan); context.SaveChanges(); return(Redirect("/NutritionPlan")); } return(View(addNutritionPlanViewModel)); }
public IActionResult Add(AddFoodViewModel addFoodViewModel) { if (ModelState.IsValid) { NutritionPlan newNutritionPlan = context.NutritionPlans.Single(n => n.ID == addFoodViewModel.NutritionPlanID); //Add new food to context and save it Food newFood = new Food { Name = addFoodViewModel.Name, Price = addFoodViewModel.Price, NutritionPlan = newNutritionPlan }; context.Foods.Add(newFood); context.SaveChanges(); return(Redirect("/Food")); } return(View(addFoodViewModel)); }
//SavePlan() saves NutritionPlan in the database public NutritionPlan SavePlan(NutritionPlanModel nutritionPlan) { //open a connection to a database FitnesspointDatabase using (var context = new FitnesspointDatabaseEntities()) { //Creating NutritionPlan object and assigning data using NutritionPlanModel class NutritionPlan nutritionPlan1 = new NutritionPlan() { Name = nutritionPlan.Name, PlanDescription = nutritionPlan.PlanDescription, Created_At = DateTime.UtcNow, Updated_At = DateTime.UtcNow, Price = nutritionPlan.Price, }; //add nutritionPlan to the database NutritionPlan using model NutritionPlan context.NutritionPlans.Add(nutritionPlan1); //save the changes to the database context.SaveChanges(); return(nutritionPlan1); } }
public async Task <IActionResult> ViewCustomer(NutritionPlan newPlan) { Notification notification = new Notification(); Customer current = _context.Customers.Where(c => c.CustomerId == newPlan.CustomerId).SingleOrDefault(); notification.Id = current.IdentityUserId; notification.controllerAction = "CustomerNutritionPlan"; notification.notificationInfo = "Your customized nutritrion plan has been updated"; NutritionPlan currentNP = _context.NutritionPlans.Where(n => n.CustomerId == newPlan.CustomerId).SingleOrDefault(); currentNP.CustomerId = newPlan.CustomerId; currentNP.Meal1Time = newPlan.Meal1Time; currentNP.Meal1Entree = newPlan.Meal1Entree; currentNP.Meal1EntreeSize = newPlan.Meal1EntreeSize; currentNP.Meal1Vegetable = newPlan.Meal1Vegetable; currentNP.Meal1VegetableSize = newPlan.Meal1VegetableSize; currentNP.Meal1Carb = newPlan.Meal1Carb; currentNP.Meal1CarbSize = newPlan.Meal1CarbSize; currentNP.Meal2Time = newPlan.Meal2Time; currentNP.Meal2Entree = newPlan.Meal2Entree; currentNP.Meal2EntreeSize = newPlan.Meal2EntreeSize; currentNP.Meal2Vegetable = newPlan.Meal2Vegetable; currentNP.Meal2VegetableSize = newPlan.Meal2VegetableSize; currentNP.Meal2Carb = newPlan.Meal2Carb; currentNP.Meal2CarbSize = newPlan.Meal2CarbSize; currentNP.Meal3Time = newPlan.Meal3Time; currentNP.Meal3Entree = newPlan.Meal3Entree; currentNP.Meal3EntreeSize = newPlan.Meal3EntreeSize; currentNP.Meal3Vegetable = newPlan.Meal3Vegetable; currentNP.Meal3VegetableSize = newPlan.Meal3VegetableSize; currentNP.Meal3Carb = newPlan.Meal3Carb; currentNP.Meal3CarbSize = newPlan.Meal3CarbSize; currentNP.Meal4Time = newPlan.Meal4Time; currentNP.Meal4Entree = newPlan.Meal4Entree; currentNP.Meal4EntreeSize = newPlan.Meal4EntreeSize; currentNP.Meal4Vegetable = newPlan.Meal4Vegetable; currentNP.Meal4VegetableSize = newPlan.Meal4VegetableSize; currentNP.Meal4Carb = newPlan.Meal4Carb; currentNP.Meal4CarbSize = newPlan.Meal4CarbSize; currentNP.Meal5Time = newPlan.Meal5Time; currentNP.Meal5Entree = newPlan.Meal5Entree; currentNP.Meal5EntreeSize = newPlan.Meal5EntreeSize; currentNP.Meal5Vegetable = newPlan.Meal5Vegetable; currentNP.Meal5VegetableSize = newPlan.Meal5VegetableSize; currentNP.Meal5Carb = newPlan.Meal5Carb; currentNP.Meal5CarbSize = newPlan.Meal5CarbSize; currentNP.Meal6Time = newPlan.Meal6Time; currentNP.Meal6Entree = newPlan.Meal6Entree; currentNP.Meal6EntreeSize = newPlan.Meal6EntreeSize; currentNP.Meal6Vegetable = newPlan.Meal6Vegetable; currentNP.Meal6VegetableSize = newPlan.Meal6VegetableSize; currentNP.Meal6Carb = newPlan.Meal6Carb; currentNP.Meal6CarbSize = newPlan.Meal6CarbSize; currentNP.Snack1Time = newPlan.Snack1Time; currentNP.Snack1 = newPlan.Snack1; currentNP.Snack1Size = newPlan.Snack1Size; currentNP.Snack2Time = newPlan.Snack2Time; currentNP.Snack2 = newPlan.Snack2; currentNP.Snack2Size = newPlan.Snack2Size; currentNP.Snack3Time = newPlan.Snack3Time; currentNP.Snack3 = newPlan.Snack3; currentNP.Snack3Size = newPlan.Snack3Size; currentNP.Supplement1 = newPlan.Supplement1; currentNP.Supplement2 = newPlan.Supplement2; currentNP.Supplement3 = newPlan.Supplement3; _context.Notifications.Add(notification); _context.SaveChanges(); return(RedirectToAction("ViewCustomer", new { customerId = newPlan.CustomerId })); }
//GET: Result public ActionResult Result(string userWeight, string userHeight, string userAge, string userGender, string userTargetWeight, string userActivityLevel) { //Muscle Growth Meal Plan LinkedList <NutritionPlan> nutritionListMuscle = new LinkedList <NutritionPlan>(); NutritionPlan Mushroom_Egg = new NutritionPlan(); Mushroom_Egg.NutritionName = "Mushroom & Pepper Egg White Omelet"; Mushroom_Egg.MealType = "Breakfast"; Mushroom_Egg.ServingAmount = "2 Omelet"; Mushroom_Egg.CalorieOfNutrition = 643; nutritionListMuscle.AddLast(Mushroom_Egg); NutritionPlan Yogurt = new NutritionPlan(); Yogurt.NutritionName = "Non-Fat Yogurt"; Yogurt.MealType = "Breakfast"; Yogurt.ServingAmount = "2 Bowl"; Yogurt.CalorieOfNutrition = 274; nutritionListMuscle.AddLast(Yogurt); NutritionPlan Apple = new NutritionPlan(); Apple.NutritionName = "Apple"; Apple.MealType = "Breakfast"; Apple.ServingAmount = "1 Apple"; Apple.CalorieOfNutrition = 94; nutritionListMuscle.AddLast(Apple); NutritionPlan Cottage_Cheese = new NutritionPlan(); Cottage_Cheese.NutritionName = "Cottage Cheese and Salsa"; Cottage_Cheese.MealType = "Lunch"; Cottage_Cheese.ServingAmount = "2 Serving"; Cottage_Cheese.CalorieOfNutrition = 688; nutritionListMuscle.AddLast(Cottage_Cheese); NutritionPlan Granola = new NutritionPlan(); Granola.NutritionName = "Granola"; Granola.MealType = "Lunch"; Granola.ServingAmount = "60 Grams"; Granola.CalorieOfNutrition = 293; nutritionListMuscle.AddLast(Granola); NutritionPlan Salmon = new NutritionPlan(); Salmon.NutritionName = "Balsamic Salmon"; Salmon.MealType = "Dinner"; Salmon.ServingAmount = "2 Serving"; Salmon.CalorieOfNutrition = 598; nutritionListMuscle.AddLast(Salmon); NutritionPlan Artichokes = new NutritionPlan(); Artichokes.NutritionName = "Artichokes"; Artichokes.MealType = "Dinner"; Artichokes.ServingAmount = "2 Serving"; Artichokes.CalorieOfNutrition = 365; nutritionListMuscle.AddLast(Artichokes); //Cardio Meal Plan LinkedList <NutritionPlan> nutritionListCardio = new LinkedList <NutritionPlan>(); NutritionPlan Steak_Egg = new NutritionPlan(); Steak_Egg.NutritionName = "Steak and Egg Hash"; Steak_Egg.MealType = "Breakfast"; Steak_Egg.ServingAmount = "1 Serving"; Steak_Egg.CalorieOfNutrition = 516; nutritionListCardio.AddLast(Steak_Egg); NutritionPlan Blueberries = new NutritionPlan(); Blueberries.NutritionName = "Blueberries"; Blueberries.MealType = "Breakfast"; Blueberries.ServingAmount = "150 Grams"; Blueberries.CalorieOfNutrition = 87; nutritionListCardio.AddLast(Blueberries); NutritionPlan Butter_Berry = new NutritionPlan(); Butter_Berry.NutritionName = "Almond Butter Berry Protein Smoothie"; Butter_Berry.MealType = "Lunch"; Butter_Berry.ServingAmount = "1 Smoothie"; Butter_Berry.CalorieOfNutrition = 448; nutritionListCardio.AddLast(Butter_Berry); NutritionPlan Butter_Celery = new NutritionPlan(); Butter_Celery.NutritionName = "Almond Butter & Celery"; Butter_Celery.MealType = "Lunch"; Butter_Celery.ServingAmount = "1 Serving"; Butter_Celery.CalorieOfNutrition = 217; nutritionListCardio.AddLast(Butter_Celery); NutritionPlan Pasta = new NutritionPlan(); Pasta.NutritionName = "Pasta la Checca"; Pasta.MealType = "Dinner"; Pasta.ServingAmount = "1 Serving"; Pasta.CalorieOfNutrition = 360; nutritionListCardio.AddLast(Pasta); NutritionPlan Cottage = new NutritionPlan(); Cottage.NutritionName = "Cottage Cheese & Cantaloupe"; Cottage.MealType = "Dinner"; Cottage.ServingAmount = "1 Serving"; Cottage.CalorieOfNutrition = 190; nutritionListCardio.AddLast(Cottage); EstimatedCalories upToTen = new EstimatedCalories(); upToTen.MaxAge = 10; upToTen.MinAge = 2; upToTen.Sedentary = 1200; upToTen.ModeratelyActive = 1400; upToTen.Active = 1650; //estimatedCalories.AddLast(upToTen); EstimatedCalories upToTwenty = new EstimatedCalories(); upToTwenty.MaxAge = 20; upToTwenty.MinAge = 11; upToTwenty.Sedentary = 2200; upToTwenty.ModeratelyActive = 2530; upToTwenty.Active = 2870; //estimatedCalories.AddLast(upToTwenty); EstimatedCalories upToThirty = new EstimatedCalories(); upToThirty.MaxAge = 30; upToThirty.MinAge = 21; upToThirty.Sedentary = 2150; upToThirty.ModeratelyActive = 2400; upToThirty.Active = 2700; //estimatedCalories.AddLast(upToThirty); EstimatedCalories upToFourtyFive = new EstimatedCalories(); upToFourtyFive.MaxAge = 45; upToFourtyFive.MinAge = 31; upToFourtyFive.Sedentary = 2100; upToFourtyFive.ModeratelyActive = 2300; upToFourtyFive.Active = 2530; //estimatedCalories.AddLast(upToFourtyFive); EstimatedCalories upToSixty = new EstimatedCalories(); upToSixty.MaxAge = 60; upToSixty.MinAge = 46; upToSixty.Sedentary = 1930; upToSixty.ModeratelyActive = 2130; upToSixty.Active = 2460; //estimatedCalories.AddLast(upToSixty); EstimatedCalories infinityAndBeyond = new EstimatedCalories(); infinityAndBeyond.MinAge = 61; infinityAndBeyond.Sedentary = 1800; infinityAndBeyond.ModeratelyActive = 2025; infinityAndBeyond.Active = 2400; //estimatedCalories.AddLast(infinityAndBeyond); LinkedList <WorkoutSchedule> workoutList = new LinkedList <WorkoutSchedule>(); WorkoutSchedule Back_Squat = new WorkoutSchedule(); Back_Squat.WorkoutName = "Back Squat"; Back_Squat.SetNumber = 4; Back_Squat.RepeatNumber = "8"; Back_Squat.WorkoutTargetArea = "Abs & Legs"; workoutList.AddLast(Back_Squat); WorkoutSchedule Barbell_Lunge = new WorkoutSchedule(); Barbell_Lunge.WorkoutName = "Barbell Lunge"; Barbell_Lunge.SetNumber = 4; Barbell_Lunge.RepeatNumber = "12"; Barbell_Lunge.WorkoutTargetArea = "Abs & Legs"; workoutList.AddLast(Barbell_Lunge); WorkoutSchedule Dumbell_Press = new WorkoutSchedule(); Dumbell_Press.WorkoutName = "Dumbbell Bench Press"; Dumbell_Press.SetNumber = 2; Dumbell_Press.RepeatNumber = "12"; Dumbell_Press.WorkoutTargetArea = "Chest & Triceps"; workoutList.AddLast(Dumbell_Press); WorkoutSchedule Double_Crunch = new WorkoutSchedule(); Double_Crunch.WorkoutName = "Double Crunch"; Double_Crunch.SetNumber = 4; Double_Crunch.RepeatNumber = "20"; Double_Crunch.WorkoutTargetArea = "Shoulders & Traps"; workoutList.AddLast(Double_Crunch); WorkoutSchedule Barbell_Deadlift = new WorkoutSchedule(); Barbell_Deadlift.WorkoutName = "Barbell Deadlift"; Barbell_Deadlift.SetNumber = 4; Barbell_Deadlift.RepeatNumber = "8"; Barbell_Deadlift.WorkoutTargetArea = "Back & Biceps"; workoutList.AddLast(Barbell_Deadlift); UserResult res = new UserResult(); res.Weight = userWeight; res.Height = userHeight; res.Age = userAge; res.Gender = userGender; res.TargetWeight = userTargetWeight; res.UserActivityLevel = userActivityLevel; //Estimated calorie consumption if (Convert.ToInt16(userAge) < 11) { res.EstimatedCalories = upToTen; } else if (Convert.ToInt16(userAge) > 10 && Convert.ToInt16(userAge) < 21) { res.EstimatedCalories = upToTwenty; } else if (Convert.ToInt16(userAge) > 20 && Convert.ToInt16(userAge) < 31) { res.EstimatedCalories = upToThirty; } else if (Convert.ToInt16(userAge) > 30 && Convert.ToInt16(userAge) < 46) { res.EstimatedCalories = upToFourtyFive; } else if (Convert.ToInt16(userAge) > 45 && Convert.ToInt16(userAge) < 60) { res.EstimatedCalories = upToSixty; } else { res.EstimatedCalories = infinityAndBeyond; } double BFP = 0.0; int kgDeficit = Convert.ToInt16(userWeight) - Convert.ToInt16(userTargetWeight); if (userGender.Equals("Female")) { double height = Convert.ToDouble(userHeight) / 100; double bmi = (Convert.ToInt16(userWeight)) / (height * height); BFP = (1.20 * bmi) + (0.23 * Convert.ToInt16(userAge)) - 5.4; if (BFP <= 13.0) { res.BFResult = "Essential Fat"; } else if (BFP > 14.0 && BFP <= 20.0) { res.BFResult = "Athletes"; } else if (BFP > 20.0 && BFP <= 24.0) { res.BFResult = "Fitness"; } else if (BFP > 24.0 && BFP <= 31.0) { res.BFResult = "Average"; } else if (BFP >= 31.0) { res.BFResult = "Obese"; } } else if (userGender.Equals("Male")) { double height = Convert.ToDouble(userHeight) / 100; double bmi = (Convert.ToInt16(userWeight)) / (height * height); BFP = (1.20 * bmi) + (0.23 * Convert.ToInt16(userAge)) - 10.8 - 5.4; if (BFP <= 5.0) { res.BFResult = "Essential Fat"; } else if (BFP > 5.0 && BFP <= 13.0) { res.BFResult = "Athletes"; } else if (BFP > 13.0 && BFP <= 17.0) { res.BFResult = "Fitness"; } else if (BFP > 17.0 && BFP <= 24.0) { res.BFResult = "Average"; } else if (BFP >= 25.0) { res.BFResult = "Obese"; } } res.FatPerc = Math.Round(BFP, 2); res.CalorieToBurn = 7860 * Math.Abs(kgDeficit); double result = 0.0; //Control of the workout schedules if (Convert.ToInt16(userTargetWeight) > Convert.ToInt16(userWeight)) { res.NutritionPlan = nutritionListMuscle; res.Message = "You need to gain " + res.CalorieToBurn; res.WorkoutSchedule = workoutList; //also do estimations, using fixed 3k calorie for muscle growth if (userActivityLevel.Equals("Sedentary")) { result = (res.CalorieToBurn) / (res.EstimatedCalories.Sedentary - 100); //res.EstimatedTimeToReachTarget = (int)Math.Ceiling(result / 7); } else if (userActivityLevel.Equals("Moderately Active")) { result = (res.CalorieToBurn) / (res.EstimatedCalories.ModeratelyActive + 70); //res.EstimatedTimeToReachTarget = (int)Math.Ceiling(result / 7); } else { result = (res.CalorieToBurn) / (res.EstimatedCalories.Active + 150); //res.EstimatedTimeToReachTarget = (int)Math.Ceiling(result / 7); } } else if (Convert.ToInt16(userTargetWeight) < Convert.ToInt16(userWeight)) { res.NutritionPlan = nutritionListCardio; res.Message = "You need to burn " + res.CalorieToBurn; //remove last 3 entries which are belong to muscle growth schedule workoutList.RemoveLast(); workoutList.RemoveLast(); workoutList.RemoveLast(); //add cardio workout schedule items WorkoutSchedule Jogging = new WorkoutSchedule(); Jogging.WorkoutName = "Jogging-Treadmill"; Jogging.SetNumber = 1; Jogging.RepeatNumber = "800 Meters"; Jogging.WorkoutTargetArea = "Fat Burn & Cardio"; workoutList.AddFirst(Jogging); WorkoutSchedule Rope_Jumping = new WorkoutSchedule(); Rope_Jumping.WorkoutName = "Rope Jumping"; Rope_Jumping.SetNumber = 6; Rope_Jumping.RepeatNumber = "1 Minute"; Rope_Jumping.WorkoutTargetArea = "Fat Burn & Cardio"; workoutList.AddFirst(Rope_Jumping); WorkoutSchedule Bicycling = new WorkoutSchedule(); Bicycling.WorkoutName = "Bicycling"; Bicycling.SetNumber = 6; Bicycling.RepeatNumber = "2 Minutes"; Bicycling.WorkoutTargetArea = "Fat Burn & Cardio"; workoutList.AddFirst(Bicycling); res.WorkoutSchedule = workoutList; //also do estimations, using fixed 3k calories for muscle growth if (userActivityLevel.Equals("Sedentary")) { result = (res.CalorieToBurn) / (res.EstimatedCalories.Sedentary - 100); //res.EstimatedTimeToReachTarget = (int)Math.Ceiling(result / 7); } else if (userActivityLevel.Equals("Moderately Active")) { result = (res.CalorieToBurn) / (res.EstimatedCalories.ModeratelyActive - 250); //res.EstimatedTimeToReachTarget = (int)Math.Ceiling(result / 7); } else { result = (res.CalorieToBurn) / (res.EstimatedCalories.Active - 400); //res.EstimatedTimeToReachTarget = (int)Math.Ceiling(result / 7); } } res.EstimatedTimeToReachTarget = (int)Math.Ceiling(result / 7) + 7; return(View(res)); }