/// <summary> /// 创建用户并关联角色 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool InsertUsers(view_sys_user_role model) { var umodel = new sys_user(); umodel.User_ID = Guid.NewGuid().ToString(); umodel.User_CreateTime = DateTime.Now; umodel.User_Email = model.User_Email; umodel.User_IsDelete = 1; umodel.User_LoginName = model.User_LoginName; umodel.User_Name = model.User_Name; umodel.User_Pwd = model.User_Pwd; var result = _Sys_UserRepositoryS.Insert(umodel); if (result > 0) { var urmodel = new sys_userrole(); urmodel.UserRole_CreateTime = DateTime.Now; urmodel.UserRole_ID = Guid.NewGuid().ToString(); urmodel.UserRole_RoleID = model.Role_ID; urmodel.UserRole_UserID = umodel.User_ID; result = _Sys_UserRoleRepositoryS.Insert(urmodel); if (result <= 0) { _Sys_UserRepositoryS.Delete(umodel); } } return(result > 0); }
public ActionResult DeleteRole(JArray selectedRows, string userId, JArray Grid1_fields, JArray Grid2_fields) { foreach (string rowId in selectedRows) { sys_userrole tmp = db.sys_userrole.Find(Convert.ToInt32(rowId)); db.sys_userrole.Remove(tmp); } db.SaveChanges(); UpdateGrid(Grid1_fields, Grid2_fields, userId); //PageContext.RegisterStartupScript(ActiveWindow.HideRefresh()); return(UIHelper.Result()); }
public ActionResult AddRole(JArray selectedRows, string userId, JArray Grid1_fields, JArray Grid2_fields) { foreach (string rowId in selectedRows) { sys_userrole tmp = new sys_userrole(); tmp.user_id = Convert.ToInt32(userId); tmp.role_id = Convert.ToInt32(rowId); tmp.create_time = DateTime.Now; db.sys_userrole.Add(tmp); } db.SaveChanges(); UpdateGrid(Grid1_fields, Grid2_fields, userId); return(UIHelper.Result()); }
public ActionResult btnCreate_Click([Bind(Include = "user_name,user_fullname,user_pwd,user_state,unit_id,user_zw")] sys_user user) { if (ModelState.IsValid) { user.create_time = DateTime.Now; user.user_pwd = Md5Helper.Encrypt(user.user_pwd); db.sys_user.Add(user); db.SaveChanges(); sys_userrole userRole = new sys_userrole(); userRole.user_id = user.user_id; userRole.role_id = 2; //默认为普通用户 userRole.create_time = DateTime.Now; db.sys_userrole.Add(userRole); db.SaveChanges(); // 关闭本窗体(触发窗体的关闭事件) PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } return(UIHelper.Result()); }
/// <summary> /// 修改用户并修改关联角色 /// </summary> /// <param name="u"></param> /// <returns></returns> public bool UpdateUsers(view_sys_user_role u) { var model = new sys_user(); model.User_ID = u.User_ID; model.User_LoginName = u.User_LoginName; model.User_Name = u.User_Name; model.User_Pwd = u.User_Pwd; model.User_Email = u.User_Email; var result = _Sys_UserRepositoryS.Update(model, p => new { p.User_LoginName, p.User_Name, p.User_Pwd, p.User_Email, p.User_CreateTime }); if (result) { var rmodel = new sys_userrole(); rmodel.UserRole_ID = u.UserRole_ID; rmodel.UserRole_RoleID = u.Role_ID; rmodel.UserRole_UserID = u.User_ID; _Sys_UserRoleRepositoryS.Update(rmodel, p => new { p.UserRole_RoleID, p.UserRole_UserID }); } return(result); }
/// <summary> /// 删除数据 /// </summary> /// <param name="entity">实体类</param> /// <returns></returns> public bool Delete(sys_userrole entity) { return(_Sys_UserRoleRepositoryS.Delete(entity)); }
/// <summary> /// 更新实体数据 /// </summary> /// <param name="entity"></param> /// <param name="updateColumns">修改字段表达式树</param> /// <returns></returns> public bool Update(sys_userrole entity, Expression <Func <sys_userrole, object> > updateColumns) { return(_Sys_UserRoleRepositoryS.Update(entity, updateColumns)); }
/// <summary> /// 更新实体数据 /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool Update(sys_userrole entity) { return(_Sys_UserRoleRepositoryS.Update(entity)); }
/// <summary> /// 写入实体数据 /// </summary> /// <param name="entity">实体类</param> /// <returns></returns> public long Insert(sys_userrole entity) { return(_Sys_UserRoleRepositoryS.Insert(entity)); }