本文整理汇总了C#中db.Database.MaxCharSlotPrice方法的典型用法代码示例。如果您正苦于以下问题:C# Database.MaxCharSlotPrice方法的具体用法?C# Database.MaxCharSlotPrice怎么用?C# Database.MaxCharSlotPrice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Database
的用法示例。
在下文中一共展示了Database.MaxCharSlotPrice方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleRequest
public override void HandleRequest(HttpListenerContext context)
{
NameValueCollection query;
using (var rdr = new StreamReader(context.Request.InputStream))
query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
using (var db = new Database(Program.Settings.GetValue("conn")))
{
Account acc = db.Verify(query["guid"], query["password"]);
int charSlots = db.MaxCharSlotPrice(query["guid"]);
byte[] status;
if (acc == null)
{
status = Encoding.UTF8.GetBytes("<Error>Account credentials not valid</Error>");
}
else
{
MySqlCommand cmd = db.CreateQuery();
cmd.CommandText = "SELECT fame FROM stats WHERE [email protected];";
cmd.Parameters.AddWithValue("@accId", acc.AccountId);
if ((int) cmd.ExecuteScalar() < charSlots)
status = Encoding.UTF8.GetBytes("<Error>Not enough fame</Error>");
else
{
cmd = db.CreateQuery();
cmd.CommandText = "UPDATE stats SET fame = fame - @price WHERE [email protected]";
cmd.Parameters.AddWithValue("@accId", acc.AccountId);
cmd.Parameters.AddWithValue("@price", charSlots);
if (cmd.ExecuteNonQuery() > 0)
{
cmd = db.CreateQuery();
cmd.CommandText = "UPDATE accounts SET maxCharSlot = maxCharSlot + 1 WHERE [email protected]";
cmd.Parameters.AddWithValue("@accId", acc.AccountId);
if (cmd.ExecuteNonQuery() > 0)
status = Encoding.UTF8.GetBytes("<Success/>");
else
status = Encoding.UTF8.GetBytes("<Error>Internal Error</Error>");
}
else
status = Encoding.UTF8.GetBytes("<Error>Internal Error</Error>");
}
}
context.Response.OutputStream.Write(status, 0, status.Length);
}
}