Beispiel #1
0
        public IActionResult Post([FromBody] Pizza pizza)
        {
            Response oResponse = new Response();

            try
            {
                var flag = _pizzaService.ValPizza(pizza);
                if (flag == true)
                {
                    _pizzaService.Create(pizza);

                    oResponse.Code    = 1;
                    oResponse.Message = "pizza registrada";
                    oResponse.Data    = pizza;
                }
                else
                {
                    oResponse.Code    = 0;
                    oResponse.Message = "pizza ya registrada";
                }
            }
            catch (Exception e)
            {
                oResponse.Message = "error al guardar pizza" + e.Message;
            }
            return(Ok(oResponse));
        }
 public IActionResult Add(Pizza pizza)
 {
     if (ModelState.IsValid)
     {
         bool isExistingPizza = false;
         try
         {
             Pizza pizzaFound = pizzaService.Get(pizza.Name);
             if (pizzaFound != null)
             {
                 isExistingPizza = true;
             }
         }
         catch (Exception ex)
         {
             return(StatusCode(StatusCodes.Status500InternalServerError, new { serverError = ex }));
         }
         if (isExistingPizza)
         {
             return(Conflict(new { error = "The pizza you are trying to add already exists." }));
         }
         else
         {
             try
             {
                 pizzaService.Create(pizza);
                 return(new CreatedAtRouteResult("GetPizzaMongo", new { name = pizza.Name }, pizza));
             }
             catch (Exception ex)
             {
                 return(StatusCode(StatusCodes.Status500InternalServerError, new { serverError = ex }));
             }
         }
     }
     return(BadRequest(ModelState));
 }
Beispiel #3
0
        public ActionResult <PizzaModel> Create(PizzaModel pizzaModel)
        {
            _pizzaService.Create(pizzaModel);

            return(CreatedAtRoute("GetPizza", new { id = pizzaModel.Id.ToString() }, pizzaModel));
        }
Beispiel #4
0
        public ActionResult <PizzaModel> Create(PizzaModel Pizza)
        {
            _pizzaService.Create(Pizza);

            return(CreatedAtRoute("GetBook", new { id = Pizza.Id.ToString() }, Pizza));
        }
Beispiel #5
0
        public ActionResult <Pizza> Create(Pizza Pizza)
        {
            _PizzaService.Create(Pizza);

            return(CreatedAtRoute("GetPizza", new { id = Pizza.Id.ToString() }, Pizza));
        }