public Beacon GetBeaconById(string uuid) { Beacon beacon = new Beacon(); using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString)) { using (SqlCommand cmd = new SqlCommand("uspSelectBeacon", con)) { cmd.CommandType = CommandType.StoredProcedure; try { cmd.Parameters.Add("@pUuid", SqlDbType.UniqueIdentifier).Value = new Guid(uuid); } catch (SqlException e) { throw e; } SqlParameter paramResp = new SqlParameter("@response", SqlDbType.Int); paramResp.Direction = ParameterDirection.Output; cmd.Parameters.Add(paramResp); con.Open(); var reader = cmd.ExecuteReader(); while (reader.Read()) { beacon.uuid = uuid; beacon.Name = reader["Name"].ToString(); beacon.Location = reader["Location"].ToString(); } } } if (String.IsNullOrWhiteSpace(beacon.uuid)) { throw new Exception("UUID not in Database."); } return(beacon); }
public bool EditBeacon(Beacon beacon) { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString)) { using (SqlCommand cmd = new SqlCommand("uspEditBeacon", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@pUuid", SqlDbType.UniqueIdentifier).Value = new Guid(beacon.uuid); cmd.Parameters.Add("@pName", SqlDbType.VarChar).Value = beacon.Name; cmd.Parameters.Add("@pLocalization", SqlDbType.VarChar).Value = beacon.Location; SqlParameter paramResp = new SqlParameter("@response", SqlDbType.Int); paramResp.Direction = ParameterDirection.Output; cmd.Parameters.Add(paramResp); con.Open(); cmd.ExecuteNonQuery(); return(Int32.Parse(paramResp.Value.ToString()) == 1); } } }