ok-admin框架,第四天用户新增
@{
ViewBag.Title = "添加用户";
Layout = null;
}
后台代码:
///
/// 新增页面
///
///
public ActionResult Add()
{
return View();
}
///
/// 新增员工
///
///
///
[HttpPost]
public string Add(SysUser _user)
{
//User _user
//实例化数据库上下文
YuanGongDb dbcontext = new YuanGongDb();
SysUser model = new SysUser();
model.username = _user.username;
model.Realname = _user.Realname;
model.PassWord = _user.PassWord;
model.phone = _user.phone;
model.depart = _user.depart;
ResponseData res = new ResponseData();//返回的数据格式code,msg
model.createtime = DateTime.Now.ToString();
model.RID = _user.RID;
dbcontext.SysUser.Add(model);
if (dbcontext.SaveChanges() > 0)
{
res.code = 0;
res.msg = "员工添加成功";
var data = JsonConvert.SerializeObject(res);
return data;
}
else
{
res.code = 1;
res.msg = "员工添加失败";
var data = JsonConvert.SerializeObject(res);
return data;
}
}