Ejemplo n.º 1
0
        public async Task <IHttpActionResult> PutFood(int id, Containers.Models.EasyInputs.EasyFood food)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            DB.Food foodDb = food.ToDBFood();
            foodDb.Id = id;

            db.Entry(foodDb).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FoodExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> PostFood(Containers.Models.EasyInputs.EasyFood food)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            FoodImg imgFoodOutput = await Containers.Foods.Add(food);

            return(CreatedAtRoute("DefaultApi", new { id = imgFoodOutput.Id }, imgFoodOutput));
        }