Exemplo n.º 1
0
 //前回Removeした中身のオブジェクトのチェック。重複しなければエラー。
 private void _addDuplicationCheck(T obj)
 {
     //1.履歴取り出し 2.NCMBRelationOperationかチェック 3.Operationが保持しているremoveListのオブジェクトをチェック
     //4.引数のobjectIdとList内のobjectIdが一つでも同じものであればOK、なければエラー
     if (this._parent._currentOperations.ContainsKey(_key))
     {
         if (this._parent._currentOperations [_key] is NCMBRelationOperation <T> )
         {
             NCMBRelationOperation <T> relationOperation = (NCMBRelationOperation <T>) this._parent._currentOperations [_key];
             if (relationOperation._relationsToRemove.Count > 0)
             {
                 bool duplication = false;                        //true:同じオブジェクト false:違うオブジェクト
                 foreach (string objectId in relationOperation._relationsToRemove)
                 {
                     if (objectId == obj.ObjectId)
                     {
                         duplication = true;
                     }
                 }
                 if (!duplication)                          //違うオブジェクトの追加を行おうとしている場合はエラー
                 {
                     throw new NCMBException(new ArgumentException("Add objects in a Remove Must be the same. Call SaveAsync() to send the data."));
                 }
             }
         }
     }
 }
 //前回Addした中身のオブジェクトをチェック。重複しなければエラー。
 private void _removeDuplicationCheck(T obj)
 {
     //objectIdとList内のobjectIdが一つでも同じものがなければエラー
     if (this._parent._currentOperations.ContainsKey(_key))
     {
         if (this._parent._currentOperations [_key] is NCMBRelationOperation <T> )
         {
             NCMBRelationOperation <T> relationOperation = (NCMBRelationOperation <T>) this._parent._currentOperations [_key];
             if (relationOperation._relationsToAdd.Count > 0)
             {
                 bool duplication = false;                        //true:同じオブジェクト false:違うオブジェクト
                 foreach (string objectId in relationOperation._relationsToAdd)
                 {
                     if (objectId == obj.ObjectId)
                     {
                         duplication = true;
                     }
                 }
                 if (!duplication)                          //違うオブジェクトの削除を行おうとしている場合はエラー
                 {
                     throw new NCMBException(new ArgumentException("Remove objects in a Add Must be the same. Call SaveAsync() to send the data."));
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// リレーションからオブジェクトの削除を行います。<br/>
        /// 前回の保存からAdd操作を行っていた場合、<br/>
        /// Add操作時と違うオブジェクトをRemoveする場合は、一度SaveAsync()を実行してください。
        /// </summary>
        /// <param name="obj">オブジェクト</param>
        public void Remove(T obj)
        {
            //すでにAddが実行されていた場合、Remove時の引数と違うobjectならばエラー
            this._removeDuplicationCheck(obj);

            HashSet <T> removeObj = new HashSet <T> ();

            removeObj.Add(obj);
            NCMBRelationOperation <T> operation = new NCMBRelationOperation <T> (null, removeObj);

            this._targetClass = operation.TargetClass;
            this._parent._performOperation(this._key, operation);
        }
Exemplo n.º 4
0
        /// <summary>
        /// リレーションにオブジェクトの追加を行います。<br/>
        /// 前回の保存からRemove操作を行っていた場合、<br/>
        /// Remove操作時と違うオブジェクトをAddする場合は、一度SaveAsync()を実行してください。
        /// </summary>
        /// <param name="obj">オブジェクト</param>
        public void Add(T obj)
        {
            //すでにRemoveが実行されていた場合、Add時の引数と違うobjectならばエラー
            this._addDuplicationCheck(obj);

            HashSet <T> addObj = new HashSet <T> ();

            addObj.Add(obj);
            NCMBRelationOperation <T> operation = new NCMBRelationOperation <T> (addObj, null);

            this._targetClass = operation.TargetClass;
            this._parent._performOperation(this._key, operation);
        }