public HttpResponseMessage Post(runopolyrunraw run) { run.creationdate = DateTime.Now; connector.RunAdd(run); var response = Request.CreateResponse(HttpStatusCode.Created, run); response.Headers.Location = new Uri(Request.RequestUri, Url.Route(null, new { id = run.id })); return response; }
public IQueryable<runopolyrun> MyRunsGet(long userid) { conn.Open(); try { string strSQL1 = "SELECT " + "a.id, " + "a.runid, " + "a.userid, " + "a.areaid, " + "a.totalkm, " + "a.areakm, " + "a.duration, " + "a.startdate, " + "a.creationdate, " + "b.name " + "from runopoly_runs a " + "left join runopoly_areas b " + "on a.areaid = b.id " + "where a.userid=" + userid.ToString(); OdbcCommand myCommand1 = new OdbcCommand(strSQL1, conn); OdbcDataReader myReader1 = myCommand1.ExecuteReader(); List<runopolyrunraw> runs = new List<runopolyrunraw>(); while (myReader1.Read()) { runopolyrunraw run = new runopolyrunraw(); run.id = Int32.Parse(myReader1.GetValue(myReader1.GetOrdinal("id")).ToString()); run.runid = Int32.Parse(myReader1.GetValue(myReader1.GetOrdinal("runid")).ToString()); run.userid = Int32.Parse(myReader1.GetValue(myReader1.GetOrdinal("userid")).ToString()); run.areaid = Int32.Parse(myReader1.GetValue(myReader1.GetOrdinal("areaid")).ToString()); run.areaname = myReader1.GetValue(myReader1.GetOrdinal("name")).ToString(); run.totalkm = Double.Parse(myReader1.GetValue(myReader1.GetOrdinal("totalkm")).ToString()); run.areakm = Double.Parse(myReader1.GetValue(myReader1.GetOrdinal("areakm")).ToString()); run.duration = Int32.Parse(myReader1.GetValue(myReader1.GetOrdinal("duration")).ToString()); run.startdate = myReader1.GetDate(myReader1.GetOrdinal("startdate")); run.creationdate = myReader1.GetDate(myReader1.GetOrdinal("creationdate")); runs.Add(run); } myReader1.Close(); conn.Close(); return (from t in GroupByRunId(runs.AsEnumerable()) select t).OrderBy(t => t.runid).AsQueryable(); } catch { return null; } }
/* public runopolyarea AreaGet(int id) { runopolyarea returnArea = null; try { string strSQL0 = "SELECT * from runopoly_areas WHERE id = " + id.ToString(); OdbcCommand myCommand0 = new OdbcCommand(strSQL0, conn); conn.Open(); OdbcDataReader myReader0 = myCommand0.ExecuteReader(); while (myReader0.Read()) { returnArea = new runopolyarea(); returnArea.id = Int32.Parse(myReader0.GetValue(myReader0.GetOrdinal("id")).ToString()); returnArea.name = myReader0.GetValue(myReader0.GetOrdinal("name")).ToString(); returnArea.longitude = Double.Parse(myReader0.GetValue(myReader0.GetOrdinal("longitude")).ToString()); returnArea.latitude = Double.Parse(myReader0.GetValue(myReader0.GetOrdinal("latitude")).ToString()); returnArea.radius1 = Int32.Parse(myReader0.GetValue(myReader0.GetOrdinal("radius1")).ToString()); returnArea.radius2 = Int32.Parse(myReader0.GetValue(myReader0.GetOrdinal("radius1")).ToString()); returnArea.rotation = Int32.Parse(myReader0.GetValue(myReader0.GetOrdinal("rotation")).ToString()); } myReader0.Close(); conn.Close(); return returnArea; } catch { return null; } } */ // Run functions public bool RunAdd(runopolyrunraw run) { conn.Open(); bool retVal = false; try { string strSQL = "INSERT INTO runopoly_runs (runid, userid, areaid, totalkm, areakm, duration, startdate, creationdate) VALUES (" + run.runid.ToString() + ", " + run.userid.ToString() + ", " + run.areaid.ToString() + ", " + run.totalkm.ToString() + ", " + run.areakm.ToString() + ", " + run.duration.ToString() + ", " + "'" + toMySQLDateTime(run.startdate) + "'," + "'" + toMySQLDateTime(run.creationdate) + "')"; OdbcCommand myCommand = new OdbcCommand(strSQL, conn); retVal = (1 == myCommand.ExecuteNonQuery()); return retVal; } catch { return retVal; } finally { conn.Close(); } }
public runopolyrunraw MyRunGet(int id) { conn.Open(); try { string strSQL1 = "SELECT " + "id, " + "runid, " + "userid, " + "areaid, " + "totalkm, " + "areakm, " + "duration, " + "startdate " + "creationdate " + "from runopoly_runs " + "where id=" + id.ToString(); OdbcCommand myCommand1 = new OdbcCommand(strSQL1, conn); OdbcDataReader myReader1 = myCommand1.ExecuteReader(); runopolyrunraw run = new runopolyrunraw(); while (myReader1.Read()) { run.id = Int32.Parse(myReader1.GetValue(myReader1.GetOrdinal("id")).ToString()); run.runid = Int32.Parse(myReader1.GetValue(myReader1.GetOrdinal("runid")).ToString()); run.userid = Int32.Parse(myReader1.GetValue(myReader1.GetOrdinal("userid")).ToString()); run.areaid = Int32.Parse(myReader1.GetValue(myReader1.GetOrdinal("areaid")).ToString()); run.totalkm = Double.Parse(myReader1.GetValue(myReader1.GetOrdinal("totalkm")).ToString()); run.areakm = Double.Parse(myReader1.GetValue(myReader1.GetOrdinal("areakm")).ToString()); run.duration = Int32.Parse(myReader1.GetValue(myReader1.GetOrdinal("duration")).ToString()); run.startdate = myReader1.GetDate(myReader1.GetOrdinal("startdate")); run.creationdate = myReader1.GetDate(myReader1.GetOrdinal("creationdate")); } myReader1.Close(); conn.Close(); return run ; } catch { return null; } }