public ActionResult Register(NewLogin nl)
        {
            //try
            //{
            string query = "insert into UserDetail(userId,password,name) values(@userId,@password,@name)";

            con.Open();
            SqlCommand cmd = new SqlCommand(query, con);

            cmd.Parameters.AddWithValue("@userId", nl.userName);
            cmd.Parameters.AddWithValue("@password", nl.password);
            cmd.Parameters.AddWithValue("@name", nl.name);
            try
            {
                SqlDataReader sda = cmd.ExecuteReader();
                if (sda.Read() != true)
                {
                    //FormsAuthentication.SetAuthCookie()
                    //HttpContext.Session.SetString("username", lp.Username);
                    //Session["username"]= lp.Username.ToString();
                    return(RedirectToAction("Index"));
                }
            }

            catch (Exception e)
            {
                ViewData["Message"] = "User already registered";
            }
            //else
            //{
            //    ViewData["Message"] = "User already registered";
            //}
            con.Close();
            return(View());
        }
예제 #2
0
        public static void StateContextQuestion()
        {
            LoginContext ctx = new LoginContext();
            NewLogin     nl  = new NewLogin(ctx);

            ctx.Init(nl);

            ctx.Login("123");
            ctx.Login("123");
            ctx.Login("123");
            ctx.Login("123");
            ctx.Login("123");
            ctx.Login("123");
            ctx.Restart();
            ctx.Login("123");
            ctx.Login("12345");
        }