public Models.GeometryRule get_geometry_rule(string id) { // /api/spectrum/get_geometry_rule/e0eb4bd0-586c-4efe-bf2d-d5d34b436f8f Guid Id = new Guid(id); Models.GeometryRule rule = new Models.GeometryRule(); using (SqlConnection conn = new SqlConnection(LorakonConnectionStrings.ConnectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("select * from SpectrumGeometryRules where ID = @id", conn); cmd.Parameters.AddWithValue("@id", Id); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { reader.Read(); rule.Id = (Guid)reader["ID"]; rule.Geometry = reader["Geometry"].ToString(); rule.Unit = reader["Unit"].ToString(); rule.Minimum = Convert.ToSingle(reader["Minimum"]); rule.Maximum = Convert.ToSingle(reader["Maximum"]); } } } return(rule); }
public IEnumerable <Models.GeometryRule> get_all_geometry_rules() { List <Models.GeometryRule> rulesList = new List <Models.GeometryRule>(); using (SqlConnection conn = new SqlConnection(LorakonConnectionStrings.ConnectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("select * from SpectrumGeometryRules", conn); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { Models.GeometryRule rule = new Models.GeometryRule( (Guid)reader["ID"], reader["Geometry"].ToString(), reader["Unit"].ToString(), Convert.ToSingle(reader["Minimum"]), Convert.ToSingle(reader["Maximum"])); rulesList.Add(rule); } } } return(rulesList); }
public IHttpActionResult update_geometry_rule(string id, [FromBody] Models.GeometryRule rule) { using (SqlConnection conn = new SqlConnection(LorakonConnectionStrings.ConnectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("update SpectrumGeometryRules set Unit=@Unit, Minimum=@Minimum, Maximum=@Maximum where Geometry=@Geometry", conn); cmd.Parameters.AddWithValue("@Unit", rule.Unit); cmd.Parameters.AddWithValue("@Minimum", rule.Minimum); cmd.Parameters.AddWithValue("@Maximum", rule.Maximum); cmd.Parameters.AddWithValue("@Geometry", rule.Geometry); cmd.ExecuteNonQuery(); } return(Ok()); }
public IHttpActionResult insert_geometry_rule([FromBody] Models.GeometryRule rule) { using (SqlConnection conn = new SqlConnection(LorakonConnectionStrings.ConnectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("insert into SpectrumGeometryRules values (@ID, @Geometry, @Unit, @Minimum, @Maximum)", conn); cmd.Parameters.AddWithValue("@ID", Guid.NewGuid()); cmd.Parameters.AddWithValue("@Geometry", rule.Geometry); cmd.Parameters.AddWithValue("@Unit", rule.Unit); cmd.Parameters.AddWithValue("@Minimum", rule.Minimum); cmd.Parameters.AddWithValue("@Maximum", rule.Maximum); cmd.ExecuteNonQuery(); } return(Ok()); }