public Emne GetEmneFromRandomId() { Emne emne = new Emne(); string queryString = "SELECT TOP 1 Id, Emneord FROM Emner ORDER BY NEWID()"; using (SqlConnection connection = new SqlConnection(ConnectionString)) { SqlCommand command = new SqlCommand(queryString, connection); command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(); try { while (reader.Read()) { emne.Id = reader.GetInt32(0); emne.EmneOrd = reader.GetString(1); } } finally { reader.Close(); } } return(emne); }
public Emne GetEmneFromId(int id) { Emne emne = new Emne(); string queryString = "SELECT * FROM Emner WHERE Id=" + id; using (SqlConnection connection = new SqlConnection(ConnectionString)) { SqlCommand command = new SqlCommand(queryString, connection); command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(); try { while (reader.Read()) { emne.Id = reader.GetInt32(0); emne.EmneOrd = reader.GetString(1); } } finally { reader.Close(); } } return(emne); }
public List <Emne> getAllItems() { List <Emne> EmneList = new List <Emne>(); string queryString = "SELECT * FROM Emner"; using (SqlConnection connection = new SqlConnection(ConnectionString)) { SqlCommand command = new SqlCommand(queryString, connection); command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(); try { while (reader.Read()) { Emne emne = new Emne(); emne.Id = reader.GetInt32(0); emne.EmneOrd = reader.GetString(1); EmneList.Add(emne); } } finally { reader.Close(); } } return(EmneList); }
public bool CreateEmne(Emne emne) { string queryString = "INSERT INTO Emner (Emneord) VALUES (@EmneOrd)"; using (SqlConnection connection = new SqlConnection(ConnectionString)) { try { SqlCommand command = new SqlCommand(queryString, connection); command.Parameters.AddWithValue("@EmneOrd", emne.EmneOrd); command.Connection.Open(); command.ExecuteNonQuery(); command.Connection.Close(); } catch (SqlException e) { throw new ArgumentException("500"); } } return(true); }
public void Put(int id, [FromBody] Emne value) { // Ingen Put nødvendig }
public void Post([FromBody] Emne value) { ManageEmner mngEmne = new ManageEmner(); mngEmne.CreateEmne(value); }