public override void RemoveObject(IDataObject objectToRemove) { if (GOUserRoleObjects == null) { return; } bool completed; int? objectToRemoveInternalId; if ((objectToRemove as GOUserRoleDataObject) == null) { _logEngine.LogError("Unable to remove null object", "The object you are trying to remove is null", "GOUserRoleObjectsDataSet.RemoveObject", null); throw new PulpException("Unable to remove Null Object."); } if (objectToRemove.IsNew) { objectToRemoveInternalId = objectToRemove.InternalObjectId; } else { objectToRemoveInternalId = GOUserRoleObjectInternalIds.ContainsKey((objectToRemove as GOUserRoleDataObject).PrimaryKeysCollection) ? (int?)GOUserRoleObjectInternalIds[(objectToRemove as GOUserRoleDataObject).PrimaryKeysCollection] : null; } if (objectToRemoveInternalId != null) { GOUserRoleDataObject value; completed = false; var count = 0; while (!completed && count++ < 15) { completed = GOUserRoleObjects.TryRemove((int)objectToRemoveInternalId, out value); } // Reinit InternalObjectId only if the object to remove is part of the current dataset if (ReferenceEquals(objectToRemove.ObjectsDataSet, this._rootObjectDataSet)) { objectToRemove.InternalObjectId = null; } if (!objectToRemove.IsNew) { int idvalue; completed = false; count = 0; while (!completed && count++ < 15) { completed = GOUserRoleObjectInternalIds.TryRemove((objectToRemove as GOUserRoleDataObject).PrimaryKeysCollection, out idvalue); } } // Delete the Role FK Index if ((objectToRemove as GOUserRoleDataObject).GORoleName != null) { if (Role_FKIndex.ContainsKey((objectToRemove as GOUserRoleDataObject).GORoleName) && Role_FKIndex[(objectToRemove as GOUserRoleDataObject).GORoleName].Contains((int)objectToRemoveInternalId)) { Role_FKIndex[(objectToRemove as GOUserRoleDataObject).GORoleName].Remove((int)objectToRemoveInternalId); if (!Role_FKIndex[(objectToRemove as GOUserRoleDataObject).GORoleName].Any()) { List <int> outvalue; var iscompleted = false; var count2 = 0; while (!iscompleted && count2++ < 15) { iscompleted = Role_FKIndex.TryRemove((objectToRemove as GOUserRoleDataObject).GORoleName, out outvalue); } } } GORoleDataObject relatedRole; if ((objectToRemove as GOUserRoleDataObject)._role_NewObjectId != null) { relatedRole = _rootObjectDataSet.GetObject(new GORoleDataObject() { IsNew = true, InternalObjectId = (objectToRemove as GOUserRoleDataObject)._role_NewObjectId }); } else { relatedRole = _rootObjectDataSet.GetObject(new GORoleDataObject((objectToRemove as GOUserRoleDataObject).GORoleName) { IsNew = false }); } if (relatedRole != null && this.RootObjectDataSet.NotifyChanges) { relatedRole.NotifyPropertyChanged("UserRoleItems", new SeenObjectCollection()); } } // Delete the User FK Index if (User_FKIndex.ContainsKey((objectToRemove as GOUserRoleDataObject).GOUserId) && User_FKIndex[(objectToRemove as GOUserRoleDataObject).GOUserId].Contains((int)objectToRemoveInternalId)) { User_FKIndex[(objectToRemove as GOUserRoleDataObject).GOUserId].Remove((int)objectToRemoveInternalId); if (!User_FKIndex[(objectToRemove as GOUserRoleDataObject).GOUserId].Any()) { List <int> outvalue; var iscompleted = false; var count2 = 0; while (!iscompleted && count2++ < 15) { iscompleted = User_FKIndex.TryRemove((objectToRemove as GOUserRoleDataObject).GOUserId, out outvalue); } } } GOUserDataObject relatedUser; if ((objectToRemove as GOUserRoleDataObject)._user_NewObjectId != null) { relatedUser = _rootObjectDataSet.GetObject(new GOUserDataObject() { IsNew = true, InternalObjectId = (objectToRemove as GOUserRoleDataObject)._user_NewObjectId }); } else { relatedUser = _rootObjectDataSet.GetObject(new GOUserDataObject((objectToRemove as GOUserRoleDataObject).GOUserId) { IsNew = false }); } if (relatedUser != null && this.RootObjectDataSet.NotifyChanges) { relatedUser.NotifyPropertyChanged("UserRoleItems", new SeenObjectCollection()); } } }
public override void AddObject(IDataObject objectToAdd, bool replaceIfExists) { var existingObject = GetObject(objectToAdd); if (!replaceIfExists && existingObject != null) { throw new PulpException("Object already exists"); } int newInternalId; if (existingObject != null) { //RemoveObject(existingObject); if (existingObject.InternalObjectId == null) { _logEngine.LogError("Error while trying to Add Object to the GOUserRoleObjectsDataSet", "The object you are trying to add doesn't have an InternalObjectId", "GOUserRoleObjectsDataSet", null); throw new PulpException("Error while trying to add an object to the dataset without InternalObjectId"); } newInternalId = (int)existingObject.InternalObjectId; objectToAdd.InternalObjectId = newInternalId; existingObject.CopyValuesFrom(objectToAdd, false); } else { newInternalId = GetNextNewInternalObjectId(); objectToAdd.InternalObjectId = newInternalId; var completed = false; var count = 0; while (!completed && count++ < 15) { completed = GOUserRoleObjects.TryAdd(newInternalId, (GOUserRoleDataObject)objectToAdd); } } if (!objectToAdd.IsNew && existingObject == null) { //The following if should not be necessary... var completed = false; if (GOUserRoleObjectInternalIds.ContainsKey(((GOUserRoleDataObject)objectToAdd).PrimaryKeysCollection)) { int value; var count2 = 0; while (!completed && count2++ < 15) { completed = GOUserRoleObjectInternalIds.TryRemove(((GOUserRoleDataObject)objectToAdd).PrimaryKeysCollection, out value); } } completed = false; var count = 0; while (!completed && count++ < 15) { completed = GOUserRoleObjectInternalIds.TryAdd(((GOUserRoleDataObject)objectToAdd).PrimaryKeysCollection, newInternalId); } } // Update relations including platform as "many" side or "one" side , pk side for one to one relations if ((objectToAdd as GOUserRoleDataObject) == null) { _logEngine.LogError("Unable to Add an object which is null", "Unable to add an object which is null", "GOUserRoleDataObject", null); throw new PulpException("Unexpected Error: Unable to Add an object which is Null."); } // Update the Role FK Index if ((objectToAdd as GOUserRoleDataObject).GORoleName != null) { if (!Role_FKIndex.ContainsKey((objectToAdd as GOUserRoleDataObject).GORoleName)) { var iscompleted = false; var count2 = 0; while (!iscompleted && count2++ < 15) { iscompleted = Role_FKIndex.TryAdd((objectToAdd as GOUserRoleDataObject).GORoleName, new List <int>()); } } if (!Role_FKIndex[(objectToAdd as GOUserRoleDataObject).GORoleName].Contains(newInternalId)) { Role_FKIndex[(objectToAdd as GOUserRoleDataObject).GORoleName].Add(newInternalId); } GORoleDataObject relatedRole; if ((objectToAdd as GOUserRoleDataObject)._role_NewObjectId != null) { relatedRole = _rootObjectDataSet.GetObject(new GORoleDataObject() { IsNew = true, InternalObjectId = (objectToAdd as GOUserRoleDataObject)._role_NewObjectId }); } else { relatedRole = _rootObjectDataSet.GetObject(new GORoleDataObject((objectToAdd as GOUserRoleDataObject).GORoleName) { IsNew = false }); } if (relatedRole != null && this.RootObjectDataSet.NotifyChanges) { relatedRole.NotifyPropertyChanged("UserRoleItems", new SeenObjectCollection()); } } // Update the User FK Index if (!User_FKIndex.ContainsKey((objectToAdd as GOUserRoleDataObject).GOUserId)) { var iscompleted = false; var count2 = 0; while (!iscompleted && count2++ < 15) { iscompleted = User_FKIndex.TryAdd((objectToAdd as GOUserRoleDataObject).GOUserId, new List <int>()); } } if (!User_FKIndex[(objectToAdd as GOUserRoleDataObject).GOUserId].Contains(newInternalId)) { User_FKIndex[(objectToAdd as GOUserRoleDataObject).GOUserId].Add(newInternalId); } GOUserDataObject relatedUser; if ((objectToAdd as GOUserRoleDataObject)._user_NewObjectId != null) { relatedUser = _rootObjectDataSet.GetObject(new GOUserDataObject() { IsNew = true, InternalObjectId = (objectToAdd as GOUserRoleDataObject)._user_NewObjectId }); } else { relatedUser = _rootObjectDataSet.GetObject(new GOUserDataObject((objectToAdd as GOUserRoleDataObject).GOUserId) { IsNew = false }); } if (relatedUser != null && this.RootObjectDataSet.NotifyChanges) { relatedUser.NotifyPropertyChanged("UserRoleItems", new SeenObjectCollection()); } }