コード例 #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));
        }
コード例 #2
0
 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));
 }
コード例 #3
0
        public ActionResult <PizzaModel> Create(PizzaModel pizzaModel)
        {
            _pizzaService.Create(pizzaModel);

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

            return(CreatedAtRoute("GetBook", new { id = Pizza.Id.ToString() }, Pizza));
        }
コード例 #5
0
ファイル: PizzaController.cs プロジェクト: genecc15/APILAB
        public ActionResult <Pizza> Create(Pizza Pizza)
        {
            _PizzaService.Create(Pizza);

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