public List <UserCheckpoint> GetList(int id) { using (SqlConnection con = new SqlConnection(this.connectionString)) { con.Open(); List <UserCheckpoint> checkpointList = new List <UserCheckpoint>(); SqlCommand cmd = new SqlCommand("select UserID, CheckpointID, Completed from UserCheckpoint where UserID = @ID", con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@ID", id); reader = cmd.ExecuteReader(); while (reader.Read()) { UserCheckpoint checkpoint = new UserCheckpoint(); checkpoint.userID = reader.GetInt32(0); checkpoint.checkpointID = reader.GetInt32(1); checkpoint.completed = reader.GetBoolean(2); checkpointList.Add(checkpoint); } reader.Close(); return(checkpointList); } }
public void Update(UserCheckpoint checkpoint) { using (SqlConnection con = new SqlConnection(this.connectionString)) { try { con.Open(); SqlTransaction tr = con.BeginTransaction(); SqlCommand cmd = new SqlCommand("update UserCheckpoint set Completed = @Completed where UserID = @UserID and CheckpointID = @CheckpointID", con, tr); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@UserID", checkpoint.userID); cmd.Parameters.AddWithValue("@CheckpointID", checkpoint.checkpointID); cmd.Parameters.AddWithValue("@Completed", checkpoint.completed); cmd.ExecuteNonQuery(); tr.Commit(); } catch (Exception e) { throw new Exception(e.Message); } } }
public UserCheckpoint Get(int UserID, int CheckpointID) { using (SqlConnection con = new SqlConnection(this.connectionString)) { con.Open(); SqlCommand cmd = new SqlCommand("select UserID, CheckpointID, Completed from UserCheckpoint where UserID = @UserID and CheckpointID = @CheckpointID", con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@UserID", UserID); cmd.Parameters.AddWithValue("@CheckpointID", CheckpointID); reader = cmd.ExecuteReader(); UserCheckpoint checkpoint = new UserCheckpoint(); while (reader.Read()) { checkpoint.userID = reader.GetInt32(0); checkpoint.checkpointID = reader.GetInt32(1); checkpoint.completed = reader.GetBoolean(2); } reader.Close(); return(checkpoint); } }
public HttpResponseMessage Update(UserCheckpoint checkpoint) { try { userCheckpointServices.Update(checkpoint); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message)); } }
public HttpResponseMessage Get(int uid, int cid) { try { UserCheckpoint checkpoint = userCheckpointServices.Get(uid, cid); return(Request.CreateResponse(HttpStatusCode.OK, checkpoint)); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message)); } }