public void RemoveFromRole()
 {
     if (isLogedIn)
     {
         NCMBRole.GetQuery().WhereEqualTo("roleName", roleName.text).FindAsync((roleList, error) =>
         {
             if (roleList.Count > 0)
             {
                 NCMBRole role = roleList[0];
                 if (role != null)
                 {
                     role.Users.Remove(NCMBUser.CurrentUser);
                     role.SaveAsync();
                 }
             }
         });
     }
 }
 public void AddToChildRole()
 {
     if (isLogedIn)
     {
         string   childRoleName = DateTime.Now.ToString("yyyyMMdd_HHmmss");
         NCMBRole childRole     = new NCMBRole(childRoleName);
         childRole.SaveAsync((NCMBException saveError) => {
             if (saveError != null)
             {
                 // エラー処理
             }
             else
             {
                 // 保存済みのロールに作成したロールを追加
                 NCMBRole.GetQuery().WhereEqualTo("roleName", roleName.text).FindAsync((roleList, findError) => {
                     if (findError != null)
                     {
                         // エラー処理
                     }
                     else
                     {
                         if (roleList.Count > 0)
                         {
                             NCMBRole bronzeRole = roleList[0];
                             if (bronzeRole != null)
                             {
                                 bronzeRole.Roles.Add(childRole);
                                 bronzeRole.SaveAsync();
                             }
                         }
                     }
                 });
             }
         });
     }
 }
Esempio n. 3
0
    public void AddRoleUserTest()
    {
        // ユーザー作成
        NCMBUser expertUser = new NCMBUser();

        expertUser.UserName = "******";
        expertUser.Password = "******";
        expertUser.SignUpAsync((error) => {
            if (error != null)
            {
                Assert.Fail(error.ErrorMessage);
            }
        });
        NCMBTestSettings.AwaitAsync();
        Assert.NotNull(expertUser.ObjectId);

        // ロール作成
        NCMBRole expertPlanRole = new NCMBRole("expertPlan");

        expertPlanRole.SaveAsync((error) => {
            if (error != null)
            {
                Assert.Fail(error.ErrorMessage);
            }
        });
        NCMBTestSettings.AwaitAsync();
        Assert.NotNull(expertPlanRole.ObjectId);

        // 空のロールを検索
        NCMBRole expertPlan = null;

        NCMBRole.GetQuery().WhereEqualTo("roleName", "expertPlan").FindAsync((roleList, error) => {
            if (error != null)
            {
                Assert.Fail(error.ErrorMessage);
            }
            else
            {
                expertPlan = roleList.FirstOrDefault();
            }
        });
        NCMBTestSettings.AwaitAsync();
        Assert.NotNull(expertPlan.ObjectId);

        // 空のロールにユーザーを追加
        expertPlan.Users.Add(expertUser);
        expertPlan.SaveAsync((error) => {
            if (error != null)
            {
                Assert.Fail(error.ErrorMessage);
            }
        });
        NCMBTestSettings.AwaitAsync();

        // ロールを検索
        expertPlan = null;
        NCMBRole.GetQuery().WhereEqualTo("roleName", "expertPlan").FindAsync((roleList, error) => {
            if (error != null)
            {
                Assert.Fail(error.ErrorMessage);
            }
            else
            {
                expertPlan = roleList.FirstOrDefault();
            }
        });
        NCMBTestSettings.AwaitAsync();

        // ロールに所属するユーザーを検索
        expertPlan.Users.GetQuery().FindAsync((userList, error) => {
            if (error != null)
            {
                Assert.Fail(error.ErrorMessage);
            }
            else
            {
                Assert.AreEqual(expertUser.ObjectId, userList.FirstOrDefault().ObjectId);
                NCMBTestSettings.CallbackFlag = true;
                // テストデータ削除
                expertPlan.DeleteAsync();
                expertUser.DeleteAsync();
            }
        });
        NCMBTestSettings.AwaitAsync();
        Assert.True(NCMBTestSettings.CallbackFlag);
    }