public POCO.Meal create(POCO.Meal meal) { if (meal == null) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(meal.Name)) { throw new ArgumentOutOfRangeException(); } var m = new Meals { Name = meal.Name, Information = meal.Information, DietPlanId = meal.DietPlanId, Alarm = meal.Alarm, Reminder = meal.Reminder }; m = _genericAccess.Add(m); meal.Id = m.Id; return(meal); }
public IActionResult Update(POCO.Meal m) { var mealService = new MealService(_genericAccess, _foodAccess, _mealAccess, _foodsInMealAccess); var foodInMealService = new FoodsInMealService(_genericAccess, _foodAccess, _mealAccess, _foodsInMealAccess); var foodService = new FoodService(_genericAccess, _foodAccess); JsonResult mealResult; JsonResult foodInMealResult; try { var ret = mealService.update(m); mealResult = Json(ret); mealResult.StatusCode = 200; } catch (Exception e) { mealResult = Json(e); mealResult.StatusCode = 400; } try { var ret = foodInMealService.updateFoodsInMeal(m); foodInMealResult = Json(ret); mealResult.StatusCode = 200; } catch (Exception e) { foodInMealResult = Json(e); foodInMealResult.StatusCode = 400; } return(mealResult); }
public bool update(POCO.Meal meal) { if (meal == null) { throw new ArgumentNullException(); } var entity = POCOObjToEntity(meal); entity = _genericAccess.Update <Meals>(entity, meal.Id); if (entity != null) { return(true); } return(false); }
// Only get basic information about meal public static POCO.Meal MealEntityToPOCO(Meals entity) { if (entity == null) { return(null); } var meal = new POCO.Meal { Id = entity.Id, Name = entity.Name, Information = entity.Information, DietPlanId = entity.DietPlanId }; return(meal); }
public bool createFoodsInMeal(POCO.Meal meal) { foreach (POCO.Food food in meal.FoodsInMeal) { FoodInMeals foodInMealEntity = new FoodInMeals { MealId = meal.Id, FoodId = food.Id, Amount = food.Amount }; foodInMealEntity = _genericAccess.Add <FoodInMeals>(foodInMealEntity); if (foodInMealEntity == null) { return(false); } } return(true); }
public static Meals POCOObjToEntity(POCO.Meal meal) { if (meal == null) { return(null); } var m = new Meals { Id = meal.Id, Name = meal.Name, Information = meal.Information, DietPlanId = meal.DietPlanId, Alarm = meal.Alarm, Reminder = meal.Reminder }; return(m); }
public IActionResult Create(POCO.Meal m) { var service = new MealService(_genericAccess, _foodAccess, _mealAccess, _foodsInMealAccess); JsonResult result; try { var meal = service.create(m); result = Json(meal); result.StatusCode = 200; } catch (Exception e) { result = Json(e); result.StatusCode = 400; } return(result); }
public static POCO.Meal EntityObjToPOCO(Meals entity) { if (entity == null) { return(null); } var meal = new POCO.Meal { Id = entity.Id, Name = entity.Name, Information = entity.Information, DietPlanId = entity.DietPlanId, Alarm = entity.Alarm, Reminder = entity.Reminder, FoodsInMeal = getPOCOFoodsInMeal(entity.FoodInMeals) }; return(meal); }
public bool updateFoodsInMeal(POCO.Meal meal) { _foodInMealsAccess.DeleteFoodsInMeal(meal.Id); return(createFoodsInMeal(meal)); }