public bool AddRole(string uId, List<int> roleIds) { UserDal userDal = new UserDal(); return userDal.AddRole(uId, roleIds); }
/// <summary>为用户添加角色 /// </summary> /// <param name="uId">用户Id</param> /// <param name="roleId">角色Id</param> /// <returns>1:成功 -1:失败 -2:已存在角色Id -3:用户不存在</returns> public int AddRole(string uId, int roleId) { UserDal userDal = new UserDal(); UserEntity userEntity = userDal.GetUser(uId); if (userEntity != null) { foreach (string item in userEntity.RolesIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) { if (item == roleId.ToString()) { return -2; } } return userDal.AddRole(uId, roleId) ? 1 : -1; } return -3; }