Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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 }) }));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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 }) }));
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        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 { }));
        }