标签:bll session lse view serial ror list() result ring
HOUTAI
D
public class UserDal
{
public int AddUser(User user)
{
SqlParameter[] parameters = new SqlParameter[]
{
new SqlParameter("@UserName",user.UserName),
new SqlParameter("@UserPassword",user.UserPassword)
};
return DBhelper.SqlExecuteNonQuery("p_Add", CommandType.StoredProcedure, parameters);
}
public int UserLogin(string Name, string Password)
{
SqlParameter[] parameters = new SqlParameter[]
{
new SqlParameter("@UserName",Name),
new SqlParameter("@UserPassword",Password)
};
var dt = DBhelper.GetTable("p_Login", CommandType.StoredProcedure, parameters);
if (dt.Rows.Count > 0)
{
return (int)dt.Rows[0]["UserID"];
}
else {
var ero = DBhelper.SqlExecuteNonQuery("p_Error", CommandType.StoredProcedure, new SqlParameter("@UserName", Name));
}
return 0;
}
public int UserUpdate(int ID, string Password)
{
SqlParameter[] parameters = new SqlParameter[]
{
new SqlParameter("@UserID",ID),
new SqlParameter("@UserPassword",Password)
};
var result = DBhelper.SqlExecuteNonQuery("p_Update", CommandType.StoredProcedure, parameters);
return result;
}
public List<User> GetUser()
{
var result = DBhelper.GetTable("p_Get", CommandType.StoredProcedure);
var jar = JsonConvert.DeserializeObject<List<User>>(JsonConvert.SerializeObject(result));
return jar;
}
}
M
public class LoginController : Controller
{
UserBll bll = new UserBll();
public ActionResult Index()
{
ViewBag.Name = Session["UName"];
return View();
}
public ActionResult Add()
{
return View();
}
public ActionResult Login()
{
ViewBag.Name = Session["UName"];
return View();
}
[LoginFatier]
public ActionResult Updata()
{
ViewBag.Name = Session["UName"];
return View();
}
[HttpPost]
public int GetUser(string Name)
{
var result = bll.GetUser().Where(m => m.UserName.Equals(Name)).ToList();
if (result.Count() > 0)
{
return 1;
}
else {
return 0;
}
}
[HttpPost]
public int Add(User user)
{
var result = bll.AddUser(user);
return result;
}
public int UserLogin(string Name,string Password)
{
var result = bll.UserLogin(Name, Password);
if (result > 0)
{
Session["UName"] = Name;
Session["ID"] = result;
}
return result;
}
public int UserUpdata(string Password)
{
int Id = Convert.ToInt32(Session["ID"]);
var result = bll.UserUpdate(Id,Password);
return result;
}
}
标签:bll session lse view serial ror list() result ring
原文地址:https://www.cnblogs.com/590-822/p/10001385.html