Untitled

 avatar
unknown
plain_text
3 years ago
1.3 kB
5
Indexable
        
 // DELETE: api/somiod/5
        [Route("api/somiod/{id:int}")]
        [HttpDelete]
        public IHttpActionResult DeleteApplication(int id)
        {
            string sql = "DELETE FROM Applications WHERE id=@id";
            SqlConnection conn = null;

            try
            {
                conn = new SqlConnection(connectionString);
                conn.Open();

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@id", id);
                //SqlDataAdapter adapter = new SqlDataAdapter();
                //adapter.DeleteCommand = cmd;

                int verifyDelete = cmd.ExecuteNonQuery();

                conn.Close();
                if (verifyDelete > 0)
                {
                    return Ok();
                }
                return NotFound();
            /*}
                conn.Close();
                if (application == null)
                {
                    return Ok();
                }
                return Ok(application);*/
            }

            catch (Exception)
            {

                if (conn.State == System.Data.ConnectionState.Open)
                    conn.Close();
                return NotFound();
            }
        }
Editor is loading...