Exemple #1
0
        public async Task <ActionResult <Dish> > PostDish(Dish dish)
        {
            //Add the userId from the token as a field
            dish.UserID = GetUserId();
            var newDish = await _dishService.Add(dish);


            return(CreatedAtAction("GetDish", new { id = dish.ID }, newDish));
        }
 public IActionResult Post([FromBody] Dish model)
 {
     try
     {
         return(Ok(_dishService.Add(model)));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Exemple #3
0
 public IActionResult CreateDish(Dish model)
 {
     try
     {
         dishService.Add(model);
         ViewBag.Msg = "Dish Created Successfully";
     }
     catch
     {
         ViewBag.Error = "Error";
     }
     ViewBag.Restaurants = restaurantService.Get();
     return(View());
 }
Exemple #4
0
 public ActionResult <string> Add([FromBody] DishVm dish)
 {
     try
     {
         ModelState.Remove("DishId");
         if (!ModelState.IsValid)
         {
             return(BadRequest("Campos inválidos"));
         }
         _dishService.Add(new Dish(dish.Name, dish.Price, dish.RestaurantId));
         return(Ok("Operação realizada com sucesso"));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
        public HttpResponseMessage Post(HttpRequestMessage request, Dish dish)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var result = dishService.Add(dish);
                    dishService.SaveChanges();
                    SaveHistory("Add new Dish with ID: " + result.ID);
                    response = request.CreateResponse(HttpStatusCode.Created, result);
                }
                return response;
            }));
        }
Exemple #6
0
 public ActionResult Add(NewDishViewModel dish)
 {
     _dishService.Add(_mapper.Map <DishModel>(dish));
     return(RedirectToAction("Index", "Menu"));
 }
Exemple #7
0
 public async Task Add([FromForm] AddDishDto dish)
 {
     await _dishService.Add(dish);
 }