Example #1
0
 /// <summary>
 /// 向该角色添加一个已有的用户
 /// </summary>
 /// <param name="roleName"></param>
 /// <param name="userID"></param>
 /// <returns></returns>
 public int AddExitUser(string roleName,int userID)
 {
     using (CarSaleEntities context = new CarSaleEntities())
     {
         var role = context.Role.FirstOrDefault(r => r.RoleName == roleName);
         RoleUserInfo newitem = new RoleUserInfo();
         newitem.RoleID = role.ID;
         newitem.UserID = userID;
         context.AddToRoleUserInfo(newitem);
         context.SaveChanges();
         return 1;
     }
 }
Example #2
0
 /// <summary>
 /// 在角色分配页面向该角色添加一个用户,RoleUserInfo表,UserInfo表都要新增一条记录
 /// </summary>
 /// <returns></returns>
 public int AddUser(string roleName,string userName,string realName)
 {
     CarSaleEntities context=new CarSaleEntities();
     UserInfoBll bll=new UserInfoBll();
     bll.AddUserInfo(userName, realName, "123456", " ", " ", " ", " ", " ", 1, " ");
     var user = context.UserInfo.FirstOrDefault(u => u.UserName == userName);
     var role = context.Role.FirstOrDefault(r => r.RoleName == roleName);
     RoleUserInfo newitem=new RoleUserInfo();
     newitem.RoleID = role.ID;
     newitem.UserID = user.ID;
     context.AddToRoleUserInfo(newitem);
     context.SaveChanges();
     return 1;
 }