public static void MapAPIEndpoints(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints) { endpoints.MapGet("/api/mealplan/craft", async(context) => { int numberOfMeals = 0, numberOfRecipesPerMeal = 0; if (!context.Request.Query.ContainsKey("number-meals") || !int.TryParse(context.Request.Query["number-meals"].ToString(), out numberOfMeals)) { await context.Response.WriteAsync("In order to make a meal plan, we need a number of meals to include in the meal plan. Please use an integer number of meals."); return; } if (!context.Request.Query.ContainsKey("recipes-per-meal") || !int.TryParse(context.Request.Query["recipes-per-meal"].ToString(), out numberOfRecipesPerMeal)) { await context.Response.WriteAsync("In order to make a meal plan, we need a number of recipes per meal to include in the meal plan. Please use an integer number of recipes."); return; } MealPlan result = new MealPlan() { Meals = new List <Meal>() }; for (int mealCounter = 0; mealCounter < numberOfMeals; mealCounter++) { Meal newMeal = new Meal() { Recipes = new List <Recipe>() }; for (int recipeCounter = 0; recipeCounter < numberOfRecipesPerMeal; recipeCounter++) { newMeal.Recipes.Add(new Recipe()); } result.Meals.Add(newMeal); } await context.Response.WriteAsJsonAsync <MealPlan>(result); }); }
public MealPlanController(IMealRepository mealRepository, MealPlan mealPlan, IPersonRepository personRepository, UserManager <User> userManager) { this.mealRepository = mealRepository; this.mealPlan = mealPlan; this.personRepository = personRepository; this.userManager = userManager; }
protected void btnCreate_Click(object sender, EventArgs e) { try { Customer customer = new Customer(); customer.find("(c.[PeopleID]='" + this.tbID.Text + "')"); if (customer.PeopleID != null) { throw new Exception("Already Exists"); } customer.PeopleID = this.tbID.Text; customer.FirstName = this.lblFirstName.Text; customer.LastName = this.lblLastName.Text; customer.PlanId = this.ddlMealPlan.SelectedValue; customer.CustomerType = this.ddlCustType.SelectedValue; MealPlan plan = new MealPlan(); plan.find("planID = '" + customer.PlanId + "'"); if (plan.PlanId != null) { customer.CurrentMeals = plan.MealsPerWeek; customer.MunchMoney = plan.MunchMoney; } customer.create(this.txtNotes.Text); this.prepareError("Created!!"); this.txtNotes.Text = ""; } catch (Exception exception) { this.lblError.Text = exception.Message; this.lblError.Visible = true; } this.tbID.Focus(); }
public async Task <Reservation> Reserve(String Name, String Email, String Country, int NoOfRooms, String RoomType, String MealPlanType, DateTime checkIn, DateTime checkOut, int TotalPrice, CancellationToken cancellationToken) { Guest guest = AddGuest(Name, Email, Country); List <Room> rooms = await getFreeRooms(RoomType, checkIn, checkOut, cancellationToken); rooms = rooms.Take(NoOfRooms).ToList(); MealPlan mealPlan = _mealPlanRepository.GetMealPlanByName(MealPlanType); RoomType roomType = Booking.converToEnum <RoomType>(RoomType); Reservation reservation = new Reservation { Guest = guest, Rooms = rooms, MealPlan = mealPlan, RoomType = roomType, StartDate = checkIn, EndDate = checkOut, Price = TotalPrice }; _reservationRepository.Add(reservation); return(reservation); }
public IActionResult GroceryList(int id = 0) { MealPlan mealPlan = mealPlanDAL.GetMealPlanById(id); List <Ingredient> groceryList = ingredientDAL.GetIngredientsByMealPlan(mealPlan); return(View(groceryList)); }
//default constructor generates it's own list of meals randomly public MealDisplay() { InitializeComponent(); meals = new MealPlan(); meals.GenerateMeals(); DataContext = meals.GetDataCollection(); }
public List <MealPlan> GroceryList(int mealPlanId) { List <MealPlan> output = new List <MealPlan>(); try { using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand cmd = new SqlCommand(GrocerySql, connection); cmd.Parameters.AddWithValue("@mealPlanId", mealPlanId); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { MealPlan grocery = new MealPlan(); grocery.Ingredient = Convert.ToString(reader["ingredient_name"]); grocery.Count = Convert.ToInt32(reader["total"]); grocery.Amount = Convert.ToString(reader["amount"]); output.Add(grocery); } } } catch (SqlException ex) { throw; } return(output); }
public IActionResult ProcessAddition(MealPlan obj, string breakfast, string lunch, string dinner, string activity) { TempData["date"] = obj.Tanggal; if (!string.IsNullOrEmpty(breakfast)) { return(RedirectToAction("SeeList", "BreakfastFoods")); } else if (!string.IsNullOrEmpty(lunch)) { return(RedirectToAction("SeeList", "LunchFoods")); } else if (!string.IsNullOrEmpty(dinner)) { return(RedirectToAction("SeeList", "DinnerFoods")); } else if (!string.IsNullOrEmpty(activity)) { return(RedirectToAction("SeeList", "TakenActivities")); } else { return(RedirectToAction(nameof(Index), new { date = TempData["date"] })); } }
private List <Meal> UpdateNewMealsIntoDatabase(MealPlan mealPlan) { // get all meals of the logged in user from the database List <Meal> myMeals = mealDAO.GetMyMeals(this.UserId); //get all id's from those meals List <int> mealIds = new List <int>(); foreach (Meal meal in myMeals) { mealIds.Add(meal.MealId); } //loop through mealplan's meal list and find meals not in the database List <Meal> newMeals = new List <Meal>(); foreach (Meal meal in mealPlan.MealList) //loops through 7 times everytime { if (!mealIds.Contains(meal.MealId)) { if (meal.recipes.Count() != 0 && meal.recipes[0].RecipeId != 0) { newMeals.Add(meal); } } } //add meals that are not in the database if (newMeals.Count > 0) { mealDAO.AddMeals(newMeals, this.UserId); mealRecipeDAO.AddMealRecipes(newMeals); } return(newMeals); }
public bool AddMealToPlan(MealPlan thisMeal) { try { using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand cmd = new SqlCommand(SQL_AddMealToPlan, connection); cmd.Parameters.AddWithValue("@MealId", thisMeal.MealPlanId); cmd.Parameters.AddWithValue("@DayNumber", thisMeal.DayNumber); cmd.Parameters.AddWithValue("@MealNumber", thisMeal.MealNumber); cmd.Parameters.AddWithValue("@RecipeId", thisMeal.RecipeId); int rowsAffected = cmd.ExecuteNonQuery(); return(rowsAffected > 0); } } catch (SqlException ex) { throw; } }
public IHttpActionResult PutMealPlan(int id, MealPlan mealPlan) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != mealPlan.Id) { return(BadRequest()); } db.Entry(mealPlan).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MealPlanExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public List <MealPlan> GetMyMealPlans(int userId) { List <MealPlan> myMealPlans = new List <MealPlan>(); try { using (SqlConnection conn = new SqlConnection(this.connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(GET_MY_MEALPLANS, conn); cmd.Parameters.AddWithValue("@userid", userId); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { MealPlan mealPlan = new MealPlan(); mealPlan.MealPlanId = Convert.ToInt32(reader["meal_plan_id"]); mealPlan.Name = Convert.ToString(reader["name"]); mealPlan.UserId = userId; mealPlan.indices = Convert.ToString(reader["meal_indices"]); myMealPlans.Add(mealPlan); } } } catch { } return(myMealPlans); }
private static void PopulateMealsIntoMealList(MealPlan mealPlan, SqlDataReader rdr) { List <int> indexList = new List <int>(); //add meal id's from indices string into indexList string[] indexes = mealPlan.indices.Split(','); for (int j = 0; j < indexes.Length; j++) { if (indexes[j] != "0") { if (rdr.Read()) { indexList.Add(Convert.ToInt32(rdr["meal_id"])); } } } //make meals and populate them into the mealList using the indexList for (int i = 0; i < indexes.Length; i++) { Meal meal = new Meal(); for (int j = 0; j < indexList.Count; j++) { string index = indexes[i]; if (index == indexList[j].ToString()) { meal.MealId = indexList[j]; } } mealPlan.MealList.Add(meal); } }
public async Task <IActionResult> PutMealPlan(long id, MealPlan mealPlan) { if (id != mealPlan.MealId) { return(BadRequest()); } _context.Entry(mealPlan).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MealPlanExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public List <MealPlan> GetPlans(int userID) { List <MealPlan> output = new List <MealPlan>(); try { using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand cmd = new SqlCommand(GetSql, connection); cmd.Parameters.AddWithValue("@userID", userID); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { MealPlan user = new MealPlan(); user.UserId = Convert.ToInt32(reader["user_id"]); user.MealPlanId = Convert.ToInt32(reader["meal_plan_id"]); user.PlanName = Convert.ToString(reader["meal_plan_name"]); output.Add(user); } } } catch (SqlException ex) { throw; } return(output); }
public void AddMealToDatabase(string name) { // TO-DO implement error handling. Check if already in database MealPlan mealPlan = new MealPlan(); Meal newMeal = new Meal() { MealName = NameInput }; mealPlan.Meals.InsertOnSubmit(newMeal); mealPlan.SubmitChanges(); IEnumerable <Meal> chosenMeal = from meal in mealPlan.Meals where meal.MealName == NameInput select meal; foreach (var meal in chosenMeal) { foreach (IngredientModel im in IngredientList) { if (im.IsChosen) { MealIngredient newMealIngredient = new MealIngredient() { MealID = meal.MealID, IngredientID = im.ID }; mealPlan.MealIngredients.InsertOnSubmit(newMealIngredient); mealPlan.SubmitChanges(); } } } }
public List <MealPlan> GetPlanDetails(int mealPlanId) { List <MealPlan> output = new List <MealPlan>(); try { using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand cmd = new SqlCommand(PlanDetailSql, connection); cmd.Parameters.AddWithValue("@mealPlanId", mealPlanId); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { MealPlan planDetails = new MealPlan(); planDetails.MealPlanId = Convert.ToInt32(reader["meal_plan_id"]); planDetails.DayNumber = Convert.ToInt32(reader["day"]); planDetails.MealNumber = Convert.ToInt32(reader["meal"]); planDetails.RecipeId = Convert.ToInt32(reader["recipe_id"]); planDetails.RecipeName = Convert.ToString(reader["recipe_name"]); planDetails.MealPlanIndex = Convert.ToInt32(reader["meal_plan_index"]); output.Add(planDetails); } } } catch (SqlException ex) { throw; } return(output); }
public async Task <IActionResult> Edit(int id, [Bind("Id,MealType,LowSeasonPrice,HighSeasonPrice")] MealPlan mealPlan) { if (id != mealPlan.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(mealPlan); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MealPlanExists(mealPlan.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(mealPlan)); }
public IActionResult UpdateMealPlan(int id, [FromBody] MealPlan item) { if (!ModelState.IsValid || item == null || item.id != id) { _logger.LogWarning(LoggingEvents.UpdateItemBadRequest, $"UPDATE({id}) BAD REQUEST"); return(BadRequest()); } var mealPlan = _context.MealPlans.FirstOrDefault(t => t.id == id); if (mealPlan == null) { _logger.LogWarning(LoggingEvents.UpdateItemNotFound, $"UPDATE(id) NOT FOUND"); return(NotFound()); } try { _context.Database.ExecuteSqlInterpolated( $@"UPDATE MealPlansView SET name = {item.name}, user = {item.user}, days = {item.days} WHERE id = {item.id}; "); } catch (Exception ex) { _logger.LogError(LoggingEvents.UpdateItemApplicationError, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(NoContent()); }
private void MealPlanCreateTest() { MealPlan meal = new MealPlan(); meal.UserID = -1; meal.RecipeID = -1; meal.PlanDate = "01/01/2016"; meal.Save(); MealPlan savedmeal = MealPlan.Get(-1, -1, meal.PlanDate); if (savedmeal == null) { testFailed("MealPlanCreateTest"); return; } else if (savedmeal.UserID.Equals(meal.UserID) && savedmeal.RecipeID.Equals(meal.RecipeID) && savedmeal.PlanDate.Equals(meal.PlanDate)) { testPassed("MealPlanCreateTest"); } else { testFailed("MealPlanCreateTest"); } savedmeal.Delete(); }
protected void btnAddToPlan_Click(object sender, EventArgs e) { DateTime date = DateTime.Now; try { date = DateTime.Parse(datepicker.Value); } catch (Exception ex) { if (Session["error"] != null) { Session.Remove("error"); } Session.Add("error", "Invalid Date."); return; } MealPlan meal = new MealPlan(); meal.UserID = mUser.ID; meal.PlanDate = date.ToString("MM/dd/yyyy"); meal.RecipeID = mRecipe.ID; meal.Save(); lblAlert.Visible = true; lblAlert.Text = $"Recipe added successfully for {date.ToString("MM/dd/yyyy")}"; }
protected void btnAdd_Click(object sender, EventArgs e) { MealPlan mp = new MealPlan(); mp.find("PlanID = '" + this.ddlMealPlan.Text + "'"); this.customer = (Customer)ViewState["customer"]; this.tbCurrentMeals.Text = (this.customer.CurrentMeals + mp.MealsPerWeek).ToString(); }
public async Task AddMealGroup(int id) { using MealPlannerContext context = new MealPlannerContext(_dbOptions); var plans = await context.MealPlans .AsNoTracking() .Where(x => x.MealGroupId == id) .Include(x => x.SideRecipes) .ToListAsync(); List <Task> tasks = new List <Task>(); foreach (var plan in plans) { var newPlan = new MealPlan { RecipeId = plan.RecipeId }; foreach (var side in plan.SideRecipes) { newPlan.SideRecipes.Add(new SideRelationship { ExcludeFromShoppingList = side.ExcludeFromShoppingList, RecipeId = side.RecipeId }); } tasks.Add(AddMealPlan(newPlan)); } await Task.WhenAll(tasks); }
public MealPlan MapRowToMealPlan(SqlDataReader reader) { MealPlan mealPlan = new MealPlan(); List <Day> days = new List <Day>(); List <int?> daysList = new List <int?>(); mealPlan.MealPlanId = Convert.ToInt32(reader["mealPlan_id"]); mealPlan.Name = Convert.ToString(reader["mealPlan_name"]); daysList.Add(reader["day1"] as int?); daysList.Add(reader["day2"] as int?); daysList.Add(reader["day3"] as int?); daysList.Add(reader["day4"] as int?); daysList.Add(reader["day5"] as int?); daysList.Add(reader["day6"] as int?); daysList.Add(reader["day7"] as int?); days.Add(GetDayInMealPlan(Convert.ToInt32(daysList[0]))); days.Add(GetDayInMealPlan(Convert.ToInt32(daysList[1]))); days.Add(GetDayInMealPlan(Convert.ToInt32(daysList[2]))); days.Add(GetDayInMealPlan(Convert.ToInt32(daysList[3]))); days.Add(GetDayInMealPlan(Convert.ToInt32(daysList[4]))); days.Add(GetDayInMealPlan(Convert.ToInt32(daysList[5]))); days.Add(GetDayInMealPlan(Convert.ToInt32(daysList[6]))); mealPlan.Days = days; return(mealPlan); }
private async Task CreateMealsToBePlanned(MealPlan mealPlan) { foreach (DateTime day in TimeTools.EachDay(mealPlan.StartDate.Value, mealPlan.EndDate.Value)) { ScheduledMeal meal1 = new ScheduledMeal(); ScheduledMeal meal2 = new ScheduledMeal(); ScheduledMeal meal3 = new ScheduledMeal(); meal1.DateOfMeal = day; meal1.Slot = 1; meal1.MealPlanId = mealPlan.MealPlanId; await _context.AddAsync(meal1); meal2.DateOfMeal = day; meal2.Slot = 2; meal2.MealPlanId = mealPlan.MealPlanId; await _context.AddAsync(meal2); meal3.DateOfMeal = day; meal3.Slot = 3; meal3.MealPlanId = mealPlan.MealPlanId; await _context.AddAsync(meal3); } await _context.SaveChangesAsync(); }
//GET meal plan and direct to view that contains all unplanned meals in a list //with an option to select a pod member to plan the meal public ActionResult ViewMealsToAssign(MealPlan mealPlan) { var mealsToAssign = _context.ScheduledMeals.Where(m => m.MealPlanId == mealPlan.MealPlanId).ToList(); var finalMealsToAssign = mealsToAssign.Where(m => m.AssignedPlannerId == 0).OrderBy(m => m.DateOfMeal).ToList(); return(View(finalMealsToAssign)); }
public ActionResult DeleteConfirmed(int id) { MealPlan mealPlan = db.MealPlans.Find(id); db.MealPlans.Remove(mealPlan); db.SaveChanges(); return(RedirectToAction("Index")); }
public void CreateMealPlan_FirstMeal_IsRandomRecipeFromCookBook() { var cookbook = new StubCookBook(); var plan = MealPlan.Create(new StubCookBook()); cookbook.GetAllRecipes().Any(x => x.Name == plan.Meals.First().Recipe.Name).ShouldBeTrue(); }
public void CheckingVeggieMeal() { sut.Assembler = veggiepreparator; sut.VeggieCompleteMeal(ProductGenerator.veggiesandwich, ProductGenerator.chocolatebar, ProductGenerator.water); MealPlan mealPlan = veggiepreparator.GetMealPlan(); Assert.Equal(3, mealPlan.MealProducts.Count); }
public void SettingUpMealPlan() { // Testing if the complete meal gets back a meal plan of 3 products sut.CompleteMeal(ProductGenerator.sandwich, ProductGenerator.chocolatebar, ProductGenerator.water); MealPlan mealPlan = preparator.GetMealPlan(); Assert.Equal(3, mealPlan.MealProducts.Count); }
public MealPlan Get(int mealPlanId) { using (var dbContext = new ApplicationDbContext()) { MealPlan mealPlan = new MealPlan(); mealPlan = dbContext.MealPlans.Where(x => x.MealPlanId == mealPlanId).Single(); return(mealPlan); } }
public MealPlanViewModel GetDisplay(int mealPlanId) { MealPlanViewModel mealPlanDisplay = new MealPlanViewModel(); MealPlan mealPlan = Get(mealPlanId); mealPlanDisplay.MealPlanId = mealPlan.MealPlanId; mealPlanDisplay.Description = mealPlan.Description; mealPlanDisplay.PhotoFilePath = mealPlan.PhotoFilePath; mealPlanDisplay.PrepTime = mealPlan.PrepTime; mealPlanDisplay.PrepTimeUnit = mealPlan.PrepTimeUnit; mealPlanDisplay.CostPerServing = mealPlan.CostPerServing; mealPlanDisplay.Active = mealPlan.Active; mealPlanDisplay.Created = (System.DateTime)mealPlan.Created; PreparationRepository preparationRepository = new PreparationRepository(); mealPlanDisplay.Preparations = preparationRepository.GetDisplayList(mealPlanId); MealPlanAssignedCategoryRepository mealPlanAssignedCategoryRepository = new MealPlanAssignedCategoryRepository(); mealPlanDisplay.MealPlanAssignedCategories = mealPlanAssignedCategoryRepository.GetDisplayList(mealPlanId); MealPlanAssignedDietPlanRepository mealPlanAssignedDietPlanRepository = new MealPlanAssignedDietPlanRepository(); mealPlanDisplay.MealPlanAssignedDietPlans = mealPlanAssignedDietPlanRepository.GetDisplayList(mealPlanId); NutrientViewModel nutrientViewModel = new NutrientViewModel(); mealPlanDisplay.NutrientDropDownList = nutrientViewModel.GetDropDownList(); MealPlanAssignedNutrientRepository mealPlanAssignedNutrientRepository = new MealPlanAssignedNutrientRepository(); mealPlanDisplay.MealPlanAssignedNutrients = mealPlanAssignedNutrientRepository.GetDisplayList(mealPlanId); MealPlanAssignedIngredientRepository mealPlanAssignedIngredientRepository = new MealPlanAssignedIngredientRepository(); mealPlanDisplay.MealPlanAssignedIngredients = mealPlanAssignedIngredientRepository.GetDisplayList(mealPlanId); MealPlanAssignedDishRepository mealPlanAssignedDishRepository = new MealPlanAssignedDishRepository(); mealPlanDisplay.MealPlanAssignedDishes = mealPlanAssignedDishRepository.GetDisplayList(mealPlanId); UomViewModel uomViewModel = new UomViewModel(); mealPlanDisplay.UomDropDownList = uomViewModel.GetDropDownList(); DishViewModel dishViewModel = new DishViewModel(); mealPlanDisplay.DishDropDownList = dishViewModel.GetDropDownList(); IngredientViewModel ingredientViewModel = new IngredientViewModel(); mealPlanDisplay.IngredientDropDownList = ingredientViewModel.GetDropDownList(); return(mealPlanDisplay); }
protected void btnSet_Click(object sender, EventArgs e) { MealPlan mp = new MealPlan(); mp.find("PlanID = '" + this.ddlMealPlan.Text + "'"); this.tbCurrentMeals.Text = mp.MealsPerWeek.ToString(); }