title: c# web api - How to return ID after post method?
body: <p>I have a post method that adds the customer into the database. But after the post is finished, what I get as a result in the postman for the CustomerID is always 0.
  Other two parameters are working fine(Name and address), and when I check into the database, id field is inserted as it should be.
  This is my post method from the controller.</p>
  
  <pre><code> [HttpPost]
      [ActionName("postCustomerBy")]
      public HttpResponseMessage Post([FromBody]Customer customer)
      {
          customer = rep.Add(customer);
          var response = Request.CreateResponse(HttpStatusCode.Created, customer);
          string uri = Url.Link("DefaultApi", new { id = customer.CustomerID });
          response.Headers.Location = new Uri(uri);
          return response;
      }
  </code></pre>
  
  <p>EDIT: This is my function for adding Customers:</p>
  
  <pre><code> public Customer Add(Customer customer)
      {
          string query = "INSERT INTO Customer(Name,Address) VALUES (@Name,@Address)";
          using (SqlConnection con = new SqlConnection(conString))
          {
              using (SqlCommand cmd = new SqlCommand(query, con))
              {
                  cmd.Parameters.AddWithValue("@Name", customer.Name);
                  cmd.Parameters.AddWithValue("@Address", customer.Address);
                  con.Open();
                  cmd.ExecuteNonQuery();
                  con.Close();
              }
              return customer;
          }
      }
  </code></pre>