本文整理汇总了C#中System.Collections.Dictionary.AddToDynamicList方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.AddToDynamicList方法的具体用法?C# Dictionary.AddToDynamicList怎么用?C# Dictionary.AddToDynamicList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.AddToDynamicList方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get
public object Get(UserTaskDetails request)
{
if (request.UserId == -1) return BadRequestResponse();
try {
var response = new Dictionary<string, dynamic> { { "success", 0 }, { "error", 0 } };
using (var conn = DbHelper.OpenConnection()) {
var cmd = new MySqlCommand {
Connection = conn,
CommandText = "GetTeamMemberDetails",
CommandType = CommandType.StoredProcedure,
};
cmd.Parameters.AddWithValue("UserId", request.UserId);
var reader = cmd.ExecuteReader();
if (reader.HasRows) {
response["success"] = 1;
var i = 0;
while (reader.Read()) {
if (i == 0) {
response["nickname"] = reader.GetString("u_nickname");
response["tname"] = reader.GetString("t_name");
}
response.AddToDynamicList("tasks", new {
taskname = reader.GetString("tsk_name"),
taskstatus = reader.IsDBNull("status") ? 0 : reader.GetInt32("status"),
time_spent = reader.IsDBNull("time_spent") ? 0 : reader.GetInt64("time_spent"),
});
i++;
}
} else {
response["error"] = 1;
response["error_msg"] = "No team members found.";
}
}
return response;
} catch (Exception e) {
Log.Error(e.Message, e);
throw;
}
}
示例2: Get
public object Get(TeamContact request)
{
if (!IsLoggedIn) return UnauthorizedResponse();
try {
using (var conn = DbHelper.OpenConnection()) {
var cmd = new MySqlCommand {
Connection = conn,
CommandText = "GetContact",
CommandType = CommandType.StoredProcedure,
};
cmd.Parameters.AddWithValue("UserId", UserId);
var response = new Dictionary<string, dynamic> { { "success", 0 }, { "error", 0 } };
var reader = cmd.ExecuteReader();
if (reader.HasRows) {
response["success"] = 1;
while (reader.Read()) {
response.AddToDynamicList("contacts", new {
id = reader.GetInt64("u_id"),
nickname = reader.GetString("u_nickname"),
firstname = reader.GetString("u_fname"),
lastname = reader.GetString("u_lastname"),
email = reader.GetBoolean("e_vsbl_tm") ? reader.GetString("u_email") : null,
phone = reader.GetBoolean("p_vsbl_tm") ? reader.GetString("u_phone") : null,
});
}
} else {
response["error"] = 1;
response["error_msg"] = "No teams or teammates found.";
}
return response;
}
} catch (Exception e) {
Log.Error(e.Message, e);
throw;
}
}
示例3: GetTasks
private object GetTasks()
{
try {
using (var conn = DbHelper.OpenConnection()) {
var cmd = new MySqlCommand {
Connection = conn,
CommandText = "GetAllAvailableTasks",
CommandType = CommandType.StoredProcedure,
};
cmd.Parameters.AddWithValue("TeamId", TeamId);
cmd.Parameters.AddWithValue("UserId", UserId);
cmd.Parameters.AddWithValue("GameId", GameId);
var response = new Dictionary<string, dynamic> { { "success", 0 }, { "error", 0 } };
var reader = cmd.ExecuteReader();
if (reader.HasRows) {
response["success"] = 1;
while (reader.Read()) {
response.AddToDynamicList("tasks", new {
requiredtsk = !reader.IsDBNull("prv_tsk_id") ? reader.GetString("prv_tsk_id") : "None",
taskid = reader.GetInt64("tsk_id"),
status = !reader.IsDBNull("status") ? reader.GetInt32("status") : 0,
user = !reader.IsDBNull("user") ? reader.GetString("user") : "0",
taskname = reader.GetString("tsk_name"),
campusid = reader.GetInt64("c_id"),
campusname = reader.GetString("c_name"),
campuslat = reader.GetDouble("c_lat"),
campuslng = reader.GetDouble("c_lng"),
});
}
} else {
response["error"] = 1;
response["error_msg"] = "No tasks found.";
}
return response;
}
} catch (Exception e) {
Log.Error(e.Message, e);
throw;
}
}
示例4: GetInitInfo
public static object GetInitInfo(long userid)
{
try {
using (var conn = DbHelper.OpenConnection()) {
var cmd = new MySqlCommand {
Connection = conn,
CommandText = "GetUserInitInfo",
CommandType = CommandType.StoredProcedure,
};
cmd.Parameters.AddWithValue("UserId", userid);
var response = new Dictionary<string, dynamic> { { "success", 0 }, { "error", 0 } };
var reader = cmd.ExecuteReader();
using (var rows = new DataTable()) {
rows.Load(reader);
reader.Close();
// This code is ported (almost) directly from PHP to C#.
// As such, there is a lot of dynamically-typed code (using the dynamic keyword),
// calls to Convert.* methods, and uses of anonymous types instead of associative arrays.
// This implementation has been /slightly/ modified from its original (uncommented)
// PHP implementation, as I had some serious trouble understanding the original
// at some points and could not see why some things were done they way they were.
//
// Anyway, you have been warned. Confusing code ahoy!
if (rows.Rows.Count != 0) {
var number = rows.Rows.Count;
response["success"] = 1;
var count = 1;
var first = false;
var i = 0;
var prvdid = 0L;
var prvqid = "";
foreach (DataRow row in rows.Rows) {
// if( $row['status'] == 1 ) $first = true;
if (!IsNull(row, "status") && (Convert.ToInt32(row["status"]) == 1)) first = true;
if (first) {
if (i == 0) {
if (!IsNull(row, "status")) {
response["userinfo"] = new {
phoneoption = row["p_vsbl_tm"],
emailoption = row["e_vsbl_tm"],
teamid = row["t_id"],
teamname = row["t_name"],
gameid = row["g_id"],
gamestart = row["start_time"],
gamefinish = row["finis_time"],
taskid = row["tsk_id"],
tasksecret = row["secret_id"],
taskname = row["tsk_name"],
campusid = row["c_id"],
campusname = row["c_name"],
campuslat = row["c_lat"],
campuslng = row["c_lng"],
};
response.AddToDynamicList("scripts", new {
dictionaryid = row["td_id"],
text = row["direction"],
audio = row["audio"],
image = row["image"],
lat = row["td_lat"],
lng = row["td_lng"],
});
string answer;
if (!IsNull(row, "q_status") && Convert.ToInt32(row["q_status"]) == 1) {
if (!IsNull(row, "answer")) {
answer = Convert.ToString(row["answer"]);
} else {
answer = "No answer assigned";
}
} else {
answer = "0";
}
response.AddToDynamicList("questions", new {
questionid = row["q_id"],
questiontype = row["q_typ_id"],
question = row["q_text"],
questionstatus = !IsNull(row, "q_status") ? row["q_status"] : 0,
answer = answer,
});
} else {
if (!IsNull(row, "g_id")) {
response["userinfo"] = new {
phoneoption = row["p_vsbl_tm"],
emailoption = row["e_vsbl_tm"],
teamid = row["t_id"],
teamname = row["t_name"],
gameid = row["g_id"],
gamestart = row["start_time"],
gamefinish = row["finis_time"],
};
} else {
response["userinfo"] = new {
phoneoption = row["p_vsbl_tm"],
emailoption = row["e_vsbl_tm"],
//.........这里部分代码省略.........
示例5: GetTeams
private object GetTeams()
{
try {
using (var conn = DbHelper.OpenConnection()) {
var cmd = new MySqlCommand {
Connection = conn,
CommandText = "GetTeams",
CommandType = CommandType.StoredProcedure,
};
var response = new Dictionary<string, dynamic> { { "success", 0 }, { "error", 0 } };
var reader = cmd.ExecuteReader();
if (reader.HasRows) {
response["success"] = 1;
var i = 0;
var teams = new List<Dictionary<string, dynamic>>();
while (reader.Read()) {
var id = reader.GetInt64("t_id");
var tname = reader.GetString("t_name");
var timeSpent = reader.IsDBNull("time_spent") ? 0 : reader.GetInt64("time_spent");
Action add = () => teams.Add(new Dictionary<string, dynamic> {
{ "id", id },
{ "tname", tname },
{ "time_spent", timeSpent },
});
if (i == 0) add();
else {
if (teams.Any(x => x["id"] == id)) teams.Single(x => x["id"] == id)["time_spent"] += timeSpent;
else add();
}
i++;
}
foreach (var t in teams) response.AddToDynamicList("teams", t);
// The original PHP service had two sort operations, this version has... this ಠ_ಠ
var teamList = ((List<dynamic>) response["teams"]);
var teamsWithTime = teamList.Where(x => x["time_spent"] != 0).ToList();
teamList.RemoveAll(x => teamsWithTime.Contains(x));
teamsWithTime.Sort((x, y) => x["time_spent"].CompareTo(y["time_spent"]));
response["teams"] = teamList.Prepend(teamsWithTime);
} else {
response["error"] = 1;
response["error_msg"] = "No teams found.";
}
return response;
}
} catch (Exception e) {
Log.Error(e.Message, e);
throw;
}
}