一.前情提要
接着之前的,新建一个控制器UserInfoController,并添加Index视图(前端框架用的easyUI)
以下是相关引用:
<link href="~/Content/themes/default/easyui.css" rel="stylesheet" />
<link href="~/Content/themes/icon.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/jquery.easyui.min.js"></script>
<script src="~/Scripts/easyui-lang-zh_CN.js"></script>
<script src="~/Scripts/datapattern.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
二.UI层搭建
UserInfoController
using OA.BLL;
using OA.IBLL;
using OA.Model;
using OA.Model.EnumType;
using OA.Model.Search;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace OA.WebApp.Controllers
{
public class UserInfoController : Controller
{
//
// GET: /UserInfo/
IUserInfoService userInfoService = new UserInfoService();
public ActionResult Index()
{
return View();
}
#region 获取用户列表数据
public ActionResult GetUserInfoList()
{
int pageIndex = Request["page"] != null ? int.Parse(Request["page"]) : 1;
int pageSize = Request["rows"] != null ? int.Parse(Request["rows"]) : 5;
int totalCount=0;
//接收搜索条件
string userName=Request["name"];
string userRemark=Request["remark"];
//构造搜索条件
UserInfoSearch userInfoSearch = new UserInfoSearch
{
userName=userName,
userRemark=userRemark,
pageIndex=pageIndex,
pageSize=pageSize,
TotalCount=totalCount
};
short delFlag = (short)DeleteEnumType.Normarl;
//根据构建好的搜索条件完成搜索
var userInfoList = userInfoService.LoadSearchEntities(userInfoSearch,delFlag);
var temp = from u in userInfoList
select new
{
ID = u.ID,
UName = u.UName,
UPwd = u.UPwd,
Remark = u.Remark,
SubTime = u.SubTime
};
return Json(new { rows = temp, total = userInfoSearch.TotalCount });
}
#endregion
#region 删除用户数据
public ActionResult DeleteUserInfo()
{
string strId = Request["strId"];
string[] strIds = strId.Split(',');
List<int> list = new List<int>();
foreach (string id in strIds)
{
list.Add(Convert.ToInt32(id));
}
//将list集合存储的要删除的记录的编号传递到业务层
if (userInfoService.DeleteEntities(list))
{
return Content("ok");
}
else
{
return Content("no");
}
}
#endregion
#region 添加用户数据
public ActionResult AddUserInfo(UserInfo userInfo)
{
userInfo.DelFlag = 0;
userInfo.ModifiedOn = DateTime.Now;
userInfo.SubTime = DateTime.Now;
userInfoService.AddEntity(userInfo);
userInfoService.CurrentDBSession.Savechanges();
return Content("ok");
}
#endregion
#region 展示要修改的数据
public ActionResult ShowEditInfo()
{
int id = int.Parse(Request["id"]);
var userInfo = userInfoService.LoadEntities(u => u.ID ==