public ActionResult <ItemResponse <int> > Insert(PizzaInsertRequest req) { ItemResponse <int> response = null; ActionResult result = null; try { int id = _pizzaService.Insert(req); if (id > 0) { response = new ItemResponse <int>(); response.Item = id; result = Ok(response); } else { result = NotFound(); } } catch (Exception ex) { result = StatusCode(500, new ErrorResponse(ex.Message)); } return(result); }
public int Insert(PizzaInsertRequest req) { int id = 0; using (var con = GetConnection()) { var cmd = con.CreateCommand(); cmd.CommandText = "dbo.Pizzas_Insert"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Name", req.Name); cmd.Parameters.Add("@Id", SqlDbType.Int).Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); id = (int)cmd.Parameters["@Id"].Value; return(id); } }