Exemple #1
0
        public void ProcessRequest(HttpContext context)
        {
            SetupHandler(context);

            XmlNode characterNode = Request.SelectSingleNode("query/character");

            if (characterNode == null)
            {
                WriteError(context, "missing_arg", "Missing character argument");
                return;
            }
            int utfCode = -1;

            if (!int.TryParse(characterNode.InnerText, out utfCode))
            {
                WriteError(context, "invalid_arg", "Invalid character");
                return;
            }
            XmlNode intentNode = Request.SelectSingleNode("query/intent");

            if (intentNode == null)
            {
                WriteError(context, "missing_arg", "Missing intent argument");
                return;
            }
            int intent = -1;

            if (!int.TryParse(intentNode.InnerText, out intent))
            {
                WriteError(context, "invalid_arg", "Invalid intent");
                return;
            }

            SqlParameter returnCode = new SqlParameter()
            {
                Direction = ParameterDirection.ReturnValue
            };

            SqlParameter[] parameters =
            {
                new SqlParameter("UserID",  context.GetUserID()),
                new SqlParameter("UTFCode", utfCode),
                new SqlParameter("Intent",  intent),
                returnCode
            };

            using (HanDatabase db = new HanDatabase())
            {
                db.ExecuteStoredProcedure("spUserLearningUpdate", parameters);
            }

            if ((int)returnCode.Value != 0)
            {
                WriteError(context, "op_failed", "Operation failed with error code: " + returnCode.Value);
                return;
            }

            Response.Save(context.Response.OutputStream);
        }
Exemple #2
0
        protected void Page_PreLoad(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                SqlParameter userID = new SqlParameter("UserID", SqlDbType.Int)
                {
                    Direction = ParameterDirection.Output
                };
                SqlParameter returnCode = new SqlParameter()
                {
                    Direction = ParameterDirection.ReturnValue
                };

                SqlParameter[] parameters =
                {
                    new SqlParameter("Username", username.Text),
                    new SqlParameter("Password", password.Text),
                    userID,
                    returnCode
                };

                using (HanDatabase db = new HanDatabase())
                {
                    db.ExecuteStoredProcedure("spUserLogin", parameters);
                }

                state = (LoginState)returnCode.Value;

                if (state == LoginState.Success)
                {
                    Session["UserID"] = userID.Value;

                    Response.Redirect("/Dictionary/");
                }
            }
        }