public static async Task <string> PostRacePoints([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "postRacePoints")] HttpRequest req, ILogger log) { try { int eventID; dynamic body = await GetBody(req.Body); string nameID = String.Join('-', body.name.ToString().ToLower().Split(' ')); int event_count = CRUDHelper.executeScalar( String.Format( "SELECT COUNT(*) FROM modestomovesdb.raceEvents WHERE nameID = '{0}'", nameID ) ); if (event_count > 0) { eventID = int.Parse( CRUDHelper.getQuery( String.Format( "SELECT eventID FROM modestomovesdb.raceEvents WHERE nameID = '{0}'", nameID ) ) [0]); Console.WriteLine( CRUDHelper.executeNonQuery( String.Format( "UPDATE modestomovesdb.raceEvents SET startDate = '{0}', description = '{1}' WHERE eventID = {2}", body.date, body.description.ToString().Replace(",", "~~~"), eventID ) ) ); } else { eventID = int.Parse( // Get new eventID CRUDHelper.getQuery( "SELECT COUNT(*) FROM modestomovesdb.raceEvents" ) [0] ) + 1; Console.WriteLine( // Insert Values into raceEvent CRUDHelper.executeNonQuery( String.Format( "INSERT INTO modestomovesdb.raceEvents VALUES ('{0}', '{1}', '{2}', '{3}')", // eventID, body.name, body.date, body.description.ToString().Replace(",", "~~~"), nameID ) ) ); } if (body.points.Count != 0) //Delete Points { CRUDHelper.executeNonQuery( String.Format( "DELETE FROM modestomovesdb.eventmap WHERE name = '{0}'", nameID ) ); } return(event_count + " " + CRUDHelper.executeNonQuery( //Insert Points String.Format( "INSERT INTO modestomovesdb.eventmap VALUES {0}", String.Join( ",", ((IEnumerable <dynamic>)body.points).Select( point => "(" + eventID + "," + point["lat"] + "," + point["lng"] + ",'" + nameID + "','" + point["type"] + "')" ) ) ) )); } catch (Exception ex) { return(ex.ToString()); } }