Example #1
0
 public JResult AddUserRole(BaseRoleUserModel model)
 {
     return _baseservice.AddUserRole(model);
 }
Example #2
0
 /// <summary>
 /// 保存职员对应角色
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int AddUserRole(BaseRoleUserModel model)
 {
     //删除角色对应数据
     const string sql = @"delete from sys_role_user where userid=@userid;";
     var roleids = model.roleid.TrimEnd(',').Split(',');
     string sqlAdd = string.Empty;
     foreach (var roleid in roleids)
     {
         sqlAdd = sqlAdd + "INSERT INTO `sys_role_user` (`innerid`,`roleid`,`userid`) VALUES (uuid(),'" + roleid + "','" + model.userid + "');";
     }
     using (var conn = Helper.GetConnection())
     {
         var tran = conn.BeginTransaction();
         try
         {
             conn.Execute(sql, new { userid = model.userid }, tran);
             conn.Execute(sqlAdd, tran);
             tran.Commit();
             return 1;
         }
         catch (Exception ex)
         {
             tran.Rollback();
             return 0;
         }
     }
 }