public ActionResult Edit(Food food)
 {
     BLLServiceGateway<IEnumerable<Category>> Categate = new BLLServiceGateway<IEnumerable<Category>>();
     var cats = Categate.GetItems("api/Category/");
     BLLServiceGateway<Food> gate = new BLLServiceGateway<Food>();
     gate.PutItems("api/Food/" + food.Id, food);
     ViewBag.CategaryId = new SelectList(cats, "Id", "Name");
     return RedirectToAction("Index");
 }
        public ActionResult Create(Food food)
        {
            BLLServiceGateway<IEnumerable<Category>> Categate = new BLLServiceGateway<IEnumerable<Category>>();
            var cats = Categate.GetItems("api/Category/");
            BLLServiceGateway<Food> gate = new BLLServiceGateway<Food>();
            ViewBag.CategaryId = new SelectList(cats, "id", "Name", food.CategaryId);

                gate.PostItems("api/Food/", food);
                return RedirectToAction("Index");

              // return View(food);
        }
Esempio n. 3
0
        public IHttpActionResult PostFood(Food food)
        {
            DALServiceGateway<Food> gate = new DALServiceGateway<Food>();

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            gate.PostItems("api/Food/", food);
            return CreatedAtRoute("DefaultApi", new { id = food.Id }, food);
        }
Esempio n. 4
0
        public void Just_check_if_model_to_form_is_working()
        {
            var food = new Food()
            {
                Name = "Banana",
                Calories = 109.9m,
                Carbs = 12.34m,
                Fats = 56.78m,
                Proteins = 90.99m
            };

            var form = Mapper.Map<EditFoodForm>(food);

            form.Name.ShouldEqual("Banana");
            form.Calories.ShouldEqual("109,9");
            form.Carbs.ShouldEqual("12,34");
            form.Fats.ShouldEqual("56,78");
            form.Proteins.ShouldEqual("90,99");
        }
Esempio n. 5
0
        public IHttpActionResult PutFood(int id, Food food)
        {
            DALServiceGateway<Food> gate = new DALServiceGateway<Food>();

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != food.Id)
            {
                return BadRequest();
            }

            if (id != food.Id)
            {
                return BadRequest();
            }

            gate.PutItems("api/Food/" + id, food);

            return StatusCode(HttpStatusCode.NoContent);
        }