public CreateMeal(IMealRepository mealRepository, MealInput meal) { this.mealRepository = mealRepository; var date = new DateTime(meal.Date.Year, meal.Date.Month, meal.Date.Day); Meal = new domain.Meal(date, meal.Description, meal.PlaceId); }
public ActionResult Edit(MealInput input) { var m = Db.Get <Meal>(input.Id); m.Name = input.Name; m.Description = input.Description; m.Category = Db.Get <Category>(input.Category); return(Json(new { Id = m.Id, Content = this.RenderView("ListItems/MealCrud", new[] { m }) })); }
public IActionResult Create([FromBody] MealInput meal) { var result = new CreateMeal(Repository, meal).Execute(); if (result == -1) { return(BadRequest("Impossible de creer le repas")); } return(Ok(result)); }
public void ShouldCreateMeal() { var mockMealRepo = new Mock <IMealRepository>(); mockMealRepo.Setup(m => m.Create(It.IsAny <domain.Meal>())).Returns(0); var date = DateTime.Now; var input = new MealInput(date, "patates", 0); var create = new CreateMeal(mockMealRepo.Object, input); var res = create.Execute(); Assert.AreEqual(0, res); }
public ActionResult Create(MealInput input) { if (!ModelState.IsValid) { return(View(input)); } var meal = Db.Insert(new Meal { Name = input.Name, Category = Db.Categories.Single(o => o.Id == input.Category), Description = input.Description }); return(Json(new { Content = this.RenderView("ListItems/MealCrud", new[] { meal }) })); }
public ActionResult Edit(int id) { var m = Db.Meals.SingleOrDefault(o => o.Id == id); if (m == null) { throw new AwesomeDemoException("this item doesn't exist anymore"); } var vm = new MealInput { Id = m.Id, Name = m.Name, Category = m.Category.Id, Description = m.Description }; return(View("create", vm)); }
public ActionResult Create(MealInput input) { if (!ModelState.IsValid) { return(View(input)); } Db.Insert(new Meal { Name = input.Name, Category = Db.Categories.Single(o => o.Id == input.Category), Description = input.Description }); return(Json(new { })); }