Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Login.Mvc.Controllers
{
using Login.BLL;
using Login.Model;
using System.Web.Mvc;
using Login.Mvc.Fatier;
public class LoginController : Controller
{
UserBll bll = new UserBll();
// GET: Login
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();
}
/// <summary>
/// 获取所有信息
/// </summary>
/// <param name="Name"></param>
/// <returns></returns>
[HttpPost]
public int GetUser(string Name)
{
var result = bll.GetUser().Where(m => m.UserName.Equals(Name)).ToList();
//int i = result.Count;
if (result.Count() > 0)
{
return 1;
}
else {
return 0;
}
}
/// <summary>
/// 注册用户
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
[HttpPost]
public int Add(User user)
{
var result = bll.AddUser(user);
return result;
}
/// <summary>
/// 用户登陆
/// </summary>
/// <param name="Name"></param>
/// <param name="Password"></param>
/// <returns></returns>
public int UserLogin(string Name,string Password)
{
var result = bll.UserLogin(Name, Password);
if (result > 0)
{
Session["UName"] = Name;
Session["ID"] = result;
//if (Session["URL"] != null)
//{
// Response.Redirect(Session["URL"].ToString());
//}
}
return result;
}
/// <summary>
///修改密码
/// </summary>
/// <param name="Password"></param>
/// <returns></returns>
public int UserUpdata(string Password)
{
int Id = Convert.ToInt32(Session["ID"]);
var result = bll.UserUpdate(Id,Password);
return result;
}
}
}