public void UpdateTest() { List <Meal> meals = MealManager.Load(); Meal meal = meals.FirstOrDefault(u => u.Description == "Breakfast"); int results = MealManager.Update(meal, true); Assert.IsTrue(results > 0); }
// PUT api/values/5 public int Put(int id, [FromBody] Meal value) { return(MealManager.Update(value)); }
public ActionResult Create(Meal meal) { var mealInfo = mealInfoManager.GetAllMealInfos().ToList(); var mealinfolist = mealInfo.Select(x => x.StudentId).Distinct().ToList(); List <MealInfo> selectedMealInfos = new List <MealInfo>(); foreach (var ml in mealinfolist) { selectedMealInfos.Add(mealInfoManager.GetAllMealInfos().Where(x => x.StudentId == ml).LastOrDefault()); } var students = studentManager.GetAllStudents().Where(x => x.IsApproved == "A" && x.Role == "U"); var exist = mealManager.GetAllMeals().Where(x => x.MealDate.ToShortDateString() == DateTime.Now.ToShortDateString()).FirstOrDefault(); //add all student to meal table if (exist == null) { foreach (var student in students) { meal.MealDate = DateTime.Now; meal.StudentId = student.StudentId; meal.Lunch = 1; meal.Dinner = 1; meal.LunchGuestMeal = 0; meal.DinnerGuestMeal = 0; mealManager.Insert(meal); } //update meal table those on/off or add guest meal foreach (var selectedMealInfo in selectedMealInfos) { var meals = mealManager.GetAllMeals().Where(x => x.StudentId == selectedMealInfo.StudentId).LastOrDefault(); if (selectedMealInfo.StartDate.Date <= meals.MealDate && meals.MealDate.Date <= selectedMealInfo.EndDate.Date) { meals.LunchGuestMeal = Convert.ToInt32(selectedMealInfo.LunchGuestMeal); meals.DinnerGuestMeal = Convert.ToInt32(selectedMealInfo.DinnerGuestMeal); if (selectedMealInfo.LunchOff == true) { meals.Lunch = 0; } else { meals.Lunch = 1; } if (selectedMealInfo.DinnerOff == true) { meals.Dinner = 0; } else { meals.Dinner = 1; } mealManager.Update(meals); } } } return(RedirectToAction("Index")); }