public async Task IntegratedTest() { int nutid = await NutritionalValue.getProductId("Cheddar cheese"); Nutrition nutrition = NutritionalValue.getNutritionalValue(nutid).Result; Assert.IsNotNull(nutrition); }
public ActionResult SaveDiet(string food, float protein, float carb, float fat, float cal, string serving, string image, int pref_ID) { DateTime dateTime = DateTime.UtcNow.Date; try { string username = null; //check if user is logged in if (HttpContext.Session.GetString("LoggedIn") != null) { //retrieve user details from respective database tables username = HttpContext.Session.GetString("Username"); foreach (var foods in HttpContext.Session.GetCart()) { using (var context = new DietPlanDBContext()) { //var diet = new DietDb { Username = username, Date = dateTime, MealTime = foods.meal_time, Meals = foods.food }; //var nutrients = new NutritionalValue { Date = dateTime, FoodImg = foods.img, Protein = foods.nprotein, Carbs = foods.ncarb, Fat = foods.nfat, Calorie = foods.ncalorie }; //context.DietDb.Add(diet); //context.NutritionalValue.Add(nutrients); //context.SaveChanges(); var diet = new DietDb { Username = username, Date = dateTime, MealTime = foods.meal_time, Meals = foods.food, PrefId = pref_ID }; context.DietDb.Add(diet); context.SaveChanges(); var nutrients = new NutritionalValue { Food = foods.food, FoodId = diet.FoodId, Date = dateTime, FoodImg = foods.img, Protein = foods.nprotein, Carbs = foods.ncarb, Fat = foods.nfat, Calorie = foods.ncalorie, MealTime = foods.meal_time }; context.NutritionalValue.Add(nutrients); context.SaveChanges(); } } } else { return(RedirectToAction("Login")); } return(View()); } catch (SqlException) { string action = this.ControllerContext.RouteData.Values["action"].ToString(); string controller = this.ControllerContext.RouteData.Values["controller"].ToString(); return(RedirectToAction("Error", new { controllerName = controller, actionName = action })); } }
private async void ExecuteGetNutrientValueAsync() { IceCreamModel.SumCal = null; IceCreamModel.SumProtein = null; IceCreamModel.SumFat = null; IsGetNutrienCommandBusy = true; if (string.IsNullOrWhiteSpace(IceCreamModel.Name)) { SnackbarMessageQueue.Enqueue("Please, Enter an ice cream name and then click."); } else { try { int nutrienId = await NutritionalValue.getProductId(IceCreamModel.Name); if (nutrienId == -1) { SnackbarMessageQueue.Enqueue("Oops... your Ice Cream name not match any nutritional value. please try change the name"); } else { Nutrition nutrition = await NutritionalValue.getNutritionalValue(nutrienId); IceCreamModel.SumCal = nutrition.Energy; IceCreamModel.SumProtein = nutrition.Protein; IceCreamModel.SumFat = nutrition.Fat; } } catch (Exception) { SnackbarMessageQueue.Enqueue("Oops... Can Not Get Nutrient Value Now.", "Ok", () => { }, false); } } IsGetNutrienCommandBusy = false; CommandManager.InvalidateRequerySuggested(); }
public async Task TestByGeneralSearch() { int nutid = await NutritionalValue.getProductId("Cheddar cheese"); Assert.AreNotEqual(-1, nutid); }
public void Add(string name, List <Ingredient> ingredients, NutritionalValue nutritionalValue) { Add(new Recipe(GetUniqueId(), name.TrimStart().TrimEnd(), ingredients, nutritionalValue)); }