Exemplo n.º 1
0
        public IHttpActionResult PostIngDish(IngDishDTO ingDishDTO)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            IngDish ingDish = new IngDish()
            {
                QuantityNeeded = ingDishDTO.QuantityNeeded,

                CreatedBy = ((ClaimsIdentity)User.Identity).GetUserId(),
                CreatedDate = DateTime.Now,
                ModifiedBy = ((ClaimsIdentity)User.Identity).GetUserId(),
                ModifiedDate = DateTime.Now,
                IsActive = true,
                RestaurantId = ((ClaimsIdentity)User.Identity).GetUserId(),

                Ingredient = db.Ingredients.Where(x => x.IngredientId == ingDishDTO.IngredientId).FirstOrDefault(),
                Dish = db.Dishes.Where(x => x.DishId == ingDishDTO.DishId).FirstOrDefault()
            };

            try
            {

                db.IngDishes.Add(ingDish);
                db.SaveChanges();

            }
            catch (Exception e)
            {
                ErrorSignal.FromCurrentContext().Raise(e);
                throw new Exception("There was a problem saving this record: " + e.Message);

            }

            return CreatedAtRoute("DefaultApi", new { id = ingDish.IngDishId }, ingDish);
        }
Exemplo n.º 2
0
        public IHttpActionResult PutIngDish(int id, IngDish ingDish)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != ingDish.IngDishId)
            {
                return BadRequest();
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!IngDishExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }