public ActionResult AdminLogin(User u) { string message = ""; if (!ModelState.IsValid) { return View(u); } else if (ModelState.IsValid) { if (UL.CheckUserLogin(u) > 0) { return RedirectToAction("AdminPage", "Main"); } else { message = "Användarnamnet eller lösenordet var ingen succé."; } } else { message = "Alla fält måste vara ifyllda."; } if (Request.IsAjaxRequest()) { return Json(message, JsonRequestBehavior.AllowGet); } else { return RedirectToAction("AdminLogin", "Main"); } }
public int CheckUserLogin(User u) { using (SqlConnection conObj = new SqlConnection(myConnection)) { //SqlCommand myCommand = new SqlCommand("uspLogin", conObj); //myCommand.CommandType = CommandType.StoredProcedure; ////myCommand.Parameters.Clear(); //myCommand.Parameters.Add(new SqlParameter("@UserName", u.UserName)); //myCommand.Parameters.Add(new SqlParameter("@Password", u.Password)); //conObj.Open(); //var a = myCommand.ExecuteNonQuery(); //return 2; SqlCommand myCommand = new SqlCommand("uspLogin", conObj); myCommand.CommandType = CommandType.StoredProcedure; myCommand.Parameters.Add(new SqlParameter("@UserName", u.UserName)); myCommand.Parameters.Add(new SqlParameter("@Password", u.Password)); conObj.Open(); return Convert.ToInt32(myCommand.ExecuteScalar()); } }