sql update working

This commit is contained in:
Jake Visser 2017-07-12 22:59:40 -07:00
commit 6afa3aaeb4
2 changed files with 34 additions and 8 deletions

View file

@ -150,8 +150,9 @@ namespace qcbadge.Controllers
} }
else else
{ {
Helpers.Sql sql = new Helpers.Sql();
if(!String.IsNullOrEmpty(advertData64)) if (!String.IsNullOrEmpty(advertData64))
{ {
byte[] bytes = Convert.FromBase64String(advertData64); byte[] bytes = Convert.FromBase64String(advertData64);
advertData = "0x" + BitConverter.ToString(bytes); advertData = "0x" + BitConverter.ToString(bytes);
@ -209,7 +210,21 @@ namespace qcbadge.Controllers
System.Diagnostics.Debug.WriteLine(bitSet[i]); System.Diagnostics.Debug.WriteLine(bitSet[i]);
} }
int rows = sql.updateBadge(badgeId, curIcon, bitSet);
System.Diagnostics.Debug.WriteLine(rows);
if(rows == 1)
{
return StatusCode(201);
}
else
{
return StatusCode(200); return StatusCode(200);
}
} }
else else

View file

@ -130,9 +130,9 @@ namespace qcbadge.Helpers
return rtn; return rtn;
} }
public void updateBadge(String code, string email, string custcode, string paycode, string qrcode) public int updateBadge(int badgeId, int curIcon, int[] bitSet)
{ {
int rtn = 0;
try try
{ {
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
@ -145,22 +145,33 @@ namespace qcbadge.Helpers
{ {
connection.Open(); connection.Open();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.Append("UPDATE " + table + " SET codeused = 1, email = '" + email + "', custcode = '" + custcode + "', paycode = '" + paycode + "', qrcode = '" + qrcode + "', datepayed = CURRENT_TIMESTAMP WHERE [requestcode] = '" + code + "';"); sb.Append("UPDATE " + table + " SET [curr] = '" + curIcon + "', ");
int z = 47;
for (int i = 0; i < 48; i++)
{
sb.Append("[" + z + "] = '" + bitSet[i] + "', ");
z = z - 1;
}
sb.Append("[lastseen] = CURRENT_TIMESTAMP WHERE [badgeid] = '" + badgeId + "';");
String sql = sb.ToString(); String sql = sb.ToString();
System.Diagnostics.Debug.WriteLine(sb.ToString());
using (SqlCommand command = new SqlCommand(sql, connection)) using (SqlCommand command = new SqlCommand(sql, connection))
{ {
int rowsAffected = command.ExecuteNonQuery(); rtn = command.ExecuteNonQuery();
} }
} }
} }
catch (SqlException e) catch (SqlException e)
{ {
Console.WriteLine(e.ToString()); System.Diagnostics.Debug.WriteLine(e.ToString());
} }
return rtn;
} }