diff --git a/qcbadge/Controllers/HomeController.cs b/qcbadge/Controllers/HomeController.cs index 507f9d2..a1f13a2 100644 --- a/qcbadge/Controllers/HomeController.cs +++ b/qcbadge/Controllers/HomeController.cs @@ -150,8 +150,9 @@ namespace qcbadge.Controllers } else { + Helpers.Sql sql = new Helpers.Sql(); - if(!String.IsNullOrEmpty(advertData64)) + if (!String.IsNullOrEmpty(advertData64)) { byte[] bytes = Convert.FromBase64String(advertData64); advertData = "0x" + BitConverter.ToString(bytes); @@ -209,7 +210,21 @@ namespace qcbadge.Controllers System.Diagnostics.Debug.WriteLine(bitSet[i]); } - return StatusCode(200); + + + int rows = sql.updateBadge(badgeId, curIcon, bitSet); + System.Diagnostics.Debug.WriteLine(rows); + + if(rows == 1) + { + return StatusCode(201); + } + else + { + return StatusCode(200); + } + + } else diff --git a/qcbadge/Helpers/Sql.cs b/qcbadge/Helpers/Sql.cs index aff68a7..986815e 100644 --- a/qcbadge/Helpers/Sql.cs +++ b/qcbadge/Helpers/Sql.cs @@ -130,9 +130,9 @@ namespace qcbadge.Helpers 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 { SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); @@ -145,22 +145,33 @@ namespace qcbadge.Helpers { connection.Open(); 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(); + System.Diagnostics.Debug.WriteLine(sb.ToString()); using (SqlCommand command = new SqlCommand(sql, connection)) { - int rowsAffected = command.ExecuteNonQuery(); + rtn = command.ExecuteNonQuery(); } } } catch (SqlException e) { - Console.WriteLine(e.ToString()); + System.Diagnostics.Debug.WriteLine(e.ToString()); } - + return rtn; }