public static async Task <string> GetAuth([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getAuth")] HttpRequest req, ILogger log) { try { // Check if google id is in admin table or participant table... return("Done: " + CRUDHelper.executeNonQuery( "DELETE FROM modestomovesdb.employees" )); } catch (Exception ex) { return(ex.ToString()); } }
public static async Task <string> DeleteEvent([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "deleteEvent")] HttpRequest req, ILogger log) { try { return(CRUDHelper.executeNonQuery( // Delete an event in the database String.Format( "DELETE FROM modestomovesdb.raceEvents WHERE nameID = '{0}'", req.Query["name"] ) ) + " Deleted " + req.Query["name"]); } catch (Exception ex) { return(ex.ToString()); } }
public static async Task <string> RegisterForEvent([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "registerForEvent")] HttpRequest req, ILogger log) { try { CRUDHelper.executeNonQuery( String.Format( "INSERT INTO modestomovesdb.eventattendees (eventID, memberID) VALUES ({0}, {1})", getEventID(req.Query["eventID"]), getMemberID(req.Query["googleID"]) ) ); return("Register Success"); } catch (Exception ex) { return(ex.ToString()); } }
public static async Task <string> UpdatePosition([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "updatePosition")] HttpRequest req, ILogger log) { try { return(CRUDHelper.executeNonQuery( String.Format( /* double check */ "UPDATE modestomovesdb.eventattendees SET xCoord = {0}, yCoord = {1} WHERE eventID = {2} AND memberID = {3}", req.Query["lat"], req.Query["lng"], getEventID(req.Query["eventID"]), getMemberID(req.Query["googleID"]) ) ) + " Changed. " + req.Query["lat"] + " , " + req.Query["lng"] + ", " + getEventID(req.Query["eventID"]) + ", " + getMemberID(req.Query["googleID"])); } catch (Exception ex) { return(ex.ToString()); } }
public static async Task <string> SetAuth([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "setAuth")] HttpRequest req, ILogger log) { try { // move google id to admin table from participant table... // int employeeID = int.Parse ( // Get new eventID // CRUDHelper.getQuery ( // "SELECT COUNT(*) FROM modestomovesdb.employees" // ) [0] // ) + 1; return("Success: " + String.Format( "INSERT INTO modestomovesdb.employees VALUES ('{0}', 'admin')", req.Query["googleID"] ) + " " + CRUDHelper.executeNonQuery( String.Format( "INSERT INTO modestomovesdb.employees VALUES ('{0}', 'admin')", req.Query["googleID"] ) )); } catch (Exception ex) { return(ex.ToString()); } }
public static async Task <string> CheckOut([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "checkOut")] HttpRequest req, ILogger log) { try { var utc = DateTime.UtcNow; TimeZoneInfo pacificZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"); var pacificTime = TimeZoneInfo.ConvertTimeFromUtc(utc, pacificZone); var format = "yyyy-MM-dd HH:mm:ss:fff"; var stringDate = pacificTime.ToString(format); var convertedBack = DateTime.ParseExact(stringDate, format, CultureInfo.InvariantCulture); return("Checked Out: " + CRUDHelper.executeNonQuery( String.Format( "UPDATE modestomovesdb.eventattendees SET checkOut = '{2}' WHERE eventID = {0} AND memberID = {1}", getEventID(req.Query["eventID"]), getMemberID(req.Query["googleID"]), convertedBack ) )); } catch (Exception ex) { return(ex.ToString()); } }
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()); } }
public static async Task <string> UpdateUser([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "updateUser")] HttpRequest req, ILogger log) { try { dynamic body = await GetBody(req.Body); int memberID = getMemberID(body.googleID.ToString()); string debug = ""; if (CRUDHelper.getQuery( String.Format( "SELECT COUNT(*) FROM modestomovesdb.medicalinfo WHERE memberID = {0}", memberID ) ) [0] == "0") { debug = "insert medical: " + CRUDHelper.executeNonQuery( String.Format( @"INSERT INTO modestomovesdb.medicalinfo VALUES ({0},{1},'{2}','{3}',{4},'{5}','{6}','{7}','{8}','{9}',{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},'{22}')", memberID, 21, "", "", 120, "", "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "" ) ); } return(debug + " " + " Update User Success: medicalprov " + CRUDHelper.executeNonQuery( // Update Medical Table String.Format( "UPDATE modestomovesdb.medicalinfo SET medicalProvider = '{1}', allergiesToMedication = '{2}', currentMedication = '{3}' WHERE memberID = {0}", memberID, body.provider, body.allergies, body.medications ) ) + " high blood pressure " + CRUDHelper.executeNonQuery( // Update Medical Table String.Format( "UPDATE modestomovesdb.medicalinfo SET highBloodPressure = {1}, heartDisease = {2}, heartAttack = {3}, stroke = {4}, vascularDisease = {5}, neuromuscularDisease = {6}, kidneyRenalDisease = {7}, bariatricSurgery = {8}, arthritis = {9}, cancer = {10}, congenitalDisease = {11}, psychiatricDisorder = {12} WHERE memberID = {0}", memberID, body.pressure, body.heart, body.heartattack, body.stroke, body.vascular, body.neuromuscular, body.kidney, body.bariatric, body.arthritis, body.cancer, body.congenital, body.psychiatric ) ) + " other " + body.otherConditions + CRUDHelper.executeNonQuery( // Update Medical Table String.Format( "UPDATE modestomovesdb.medicalinfo SET otherConditions = '{1}' WHERE memberID = {0}", memberID, body.otherConditions ) ) + " phone " + body.emergtel + CRUDHelper.executeNonQuery( // Update Medical Table String.Format( "UPDATE modestomovesdb.medicalinfo SET ecPhone = '{1}' WHERE memberID = {0}", memberID, body.emergtel ) ) + " name " + body.emergname + CRUDHelper.executeNonQuery( // Update Medical Table String.Format( "UPDATE modestomovesdb.medicalinfo SET ecName = '{1}' WHERE memberID = {0}", memberID, body.emergname ) ) + " age and weight " + body.age + body.weight + CRUDHelper.executeNonQuery( // Update Medical Table String.Format( "UPDATE modestomovesdb.medicalinfo SET age = {1}, weight = {2} WHERE memberID = {0}", memberID, body.age, body.weight ) ) + " height " + body.height + CRUDHelper.executeNonQuery( // Update Medical Table String.Format( "UPDATE modestomovesdb.medicalinfo SET height = '{1}' WHERE memberID = {0}", memberID, body.height ) ) + " gender " + body.gender + CRUDHelper.executeNonQuery( // Update Medical Table String.Format( "UPDATE modestomovesdb.medicalinfo SET gender = '{1}' WHERE memberID = {0}", memberID, body.gender ) ) + " phone " + CRUDHelper.executeNonQuery( // Update Member Table String.Format( "UPDATE modestomovesdb.members SET phone = '{1}', bio = '{2}' WHERE googleID = '{0}'", body.googleID, body.tel, body.biography ) )); } catch (Exception ex) { return(ex.ToString()); } }
public static async Task <string> GetEventMember([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getEventMember")] HttpRequest req, ILogger log) { try { string checked_in = ""; string checked_out = ""; if (checkUser("modestomovesdb.members", "googleID", req.Query["googleID"]) == false) { CRUDHelper.executeNonQuery( // Create a new entry in the database String.Format( "INSERT INTO modestomovesdb.members (googleID, lastName, firstName, email) VALUES ('{0}', '{1}', '{2}', '{3}')", req.Query["googleID"], req.Query["lastName"], req.Query["firstName"], req.Query["email"] ) ); } int memberID = int.Parse( CRUDHelper.getQuery( String.Format( "SELECT memberID FROM modestomovesdb.members WHERE googleID = {0}", req.Query["googleID"] ) ) [0] ); CRUDHelper.executeNonQuery( String.Format( @"INSERT INTO modestomovesdb.medicalinfo VALUES ({0},{1},'{2}','{3}',{4},'{5}','{6}','{7}','{8}','{9}',{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},'{22}')", memberID, 21, "", "", 120, "", "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Something witty!" ) ); int has_registered = int.Parse( CRUDHelper.getQuery( String.Format( "SELECT COUNT(*) FROM modestomovesdb.eventAttendees WHERE memberID = {0} AND eventID = {1}", memberID, getEventID(req.Query["eventID"]) ) ) [0] ); if (has_registered == 1) { checked_in = CRUDHelper.getQuery( String.Format( "SELECT checkIn FROM modestomovesdb.eventAttendees WHERE memberID = {0} AND eventID = {1}", memberID, getEventID(req.Query["eventID"]) ) ) [0]; checked_out = CRUDHelper.getQuery( String.Format( "SELECT checkOut FROM modestomovesdb.eventAttendees WHERE memberID = {0} AND eventID = {1}", memberID, getEventID(req.Query["eventID"]) ) ) [0]; } int is_admin = int.Parse( CRUDHelper.getQuery( String.Format( "SELECT COUNT(*) FROM modestomovesdb.employees WHERE googleID = {0}", req.Query["googleID"] ) ) [0] ); return(String.Format( "{{ \"has_registered\": \"{0}\", \"checked_in\": \"{1}\", \"checked_out\": \"{2}\", \"is_admin\": \"{3}\" }}", has_registered, checked_in, checked_out, is_admin )); } catch (Exception ex) { return(ex.ToString()); } }
public static async Task <string> GetMember([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getMember")] HttpRequest req, ILogger log) { try { if (CRUDHelper.getQuery( String.Format( "SELECT COUNT(*) FROM modestomovesdb.members WHERE googleID = {0}", req.Query["googleID"] ) ) [0] != "1") { CRUDHelper.executeNonQuery( // Create a new entry in the database String.Format( "INSERT INTO modestomovesdb.members (googleID, lastName, firstName, email) VALUES ('{0}', '{1}', '{2}', '{3}')", req.Query["googleID"], req.Query["lastName"], req.Query["firstName"], req.Query["email"] ) ); } string member_info = CRUDHelper.getQuery( // Run get query from the DB String.Format( "SELECT * FROM modestomovesdb.members WHERE googleID = {0}", req.Query["googleID"] ) ) [0]; string debug = ""; if (CRUDHelper.getQuery( String.Format( "SELECT COUNT(*) FROM modestomovesdb.medicalinfo WHERE memberID = {0}", member_info.Split(',') [0] ) ) [0] != "1") { debug = "insert medical: " + CRUDHelper.executeNonQuery( String.Format( @"INSERT INTO modestomovesdb.medicalinfo VALUES ({0},{1},'{2}','{3}',{4},'{5}','{6}','{7}','{8}','{9}',{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},'{22}')", member_info.Split(',') [0], 21, "", "", 120, "", "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "" ) ); } string medical_info = CRUDHelper.getQuery( String.Format( "SELECT * FROM modestomovesdb.medicalinfo WHERE memberID = {0}", member_info.Split(',') [0] ) ) [0]; int is_admin = int.Parse( CRUDHelper.getQuery( String.Format( "SELECT COUNT(*) FROM modestomovesdb.employees WHERE googleID = {0}", req.Query["googleID"] ) ) [0] ); return(String.Format( "{{ \"member_info\": \"{0}\", \"medical_info\": \"{1}\", \"is_admin\": {2}, \"debug\": \"{3}\" }}", member_info, medical_info, is_admin, debug )); } catch (Exception ex) { return(ex.ToString() + " " + CRUDHelper.getQuery( String.Format( "SELECT * FROM modestomovesdb.members WHERE googleID = {0}", req.Query["googleID"] ) ) [0]); } }