///-------------------------------------------------------------------------------- /// <summary>This method updates the view model data and sends update command back /// to the solution builder.</summary> ///-------------------------------------------------------------------------------- protected override void OnUpdate() { // send update for any updated children foreach (EntityReferenceViewModel item in EntityReferences) { if (item.IsEdited == true) { item.Update(); } } // send update for any new children foreach (EntityReferenceViewModel item in ItemsToAdd.OfType <EntityReferenceViewModel>()) { item.Update(); EntityReferences.Add(item); } ItemsToAdd.Clear(); // send delete for any deleted children foreach (EntityReferenceViewModel item in ItemsToDelete.OfType <EntityReferenceViewModel>()) { item.Delete(); EntityReferences.Remove(item); } ItemsToDelete.Clear(); // reset modified for children foreach (EntityReferenceViewModel item in EntityReferences) { item.ResetModified(false); } }
private void GetItemsToDelete() { DataTable dttItemsToDelete = new DataTable(typeof(T).ToString()); dttItemsToDelete.Columns.Add("ID", typeof(int)); this.ItemsToDelete = (from site in lstSite where !this.Any(c => c.ID.Equals(site.ID) && site.ID > 0 && c.ID > 0) select site.ID).ToList(); DataRow row; ItemsToDelete.ForEach(delegate(int ID) { row = dttItemsToDelete.NewRow(); row["ID"] = ID; dttItemsToDelete.Rows.Add(ID); lstSite.RemoveAll(c => c.ID == ID); } ); if (dttItemsToDelete.Rows.Count > 0) { oDAL.BulkInsert(dttItemsToDelete, "Robo_" + Table + "Excluir", true); errorDelete = dttItemsToDelete.Rows.Count - this.ApagarRegistroInexistente(); } }
public virtual void Save(ORM.Database database) { lock (Locker) { foreach (var item in Items.Where(item => !item.Value.IsTemporarily)) { if (item.Value.Record.IsNew) { database.Insert(item.Value.Record); item.Value.OnPersistantItemAdded(); item.Value.Record.IsNew = false; } else if (item.Value.Record.IsDirty) { database.Update(item.Value.Record); item.Value.OnPersistantItemUpdated(); } } while (ItemsToDelete.Count > 0) { var item = ItemsToDelete.Dequeue(); database.Delete(item.Record); item.OnPersistantItemDeleted(); } } }
public IList <DataRequest> SplitByType() { var result = new List <DataRequest>(); var groups = ItemsToPut.GroupBy(i => i.FullTypeName); foreach (var group in groups) { var request = new PutRequest(group.Key) { Items = group.ToList() }; result.Add(request); } groups = ItemsToDelete.GroupBy(i => i.FullTypeName); foreach (var group in groups) { var items = group.ToList(); foreach (var item in items) { var request = new RemoveRequest(group.Key, item.PrimaryKey); result.Add(request); } } return(result); }
private static ItemsToDelete GenerateItemsToDeleteModel(IEnumerable <KbItem> currentKnowledgeBaseItems, List <QnAItem> qnaItems) { var kbIdsToDelete = new List <int>(); foreach (var kbItem in currentKnowledgeBaseItems) { var kbItemIdMetaDataItem = kbItem.metadata.FirstOrDefault(m => m.name == "itemid"); if (kbItemIdMetaDataItem != null) { //id convert var qnaItem = qnaItems.FirstOrDefault(f => f.ItemId.ToString() == kbItemIdMetaDataItem.value); if (qnaItem == null) { kbIdsToDelete.Add(kbItem.qnaId); } } else { kbIdsToDelete.Add(kbItem.qnaId); } } var itemsToDeleteModel = new ItemsToDelete() { qnaIds = kbIdsToDelete.ToArray(), sources = new string[] { }, users = new object[] { } }; return(itemsToDeleteModel); }
///-------------------------------------------------------------------------------- /// <summary>This method updates the view model data and sends update command back /// to the solution builder.</summary> ///-------------------------------------------------------------------------------- protected override void OnUpdate() { // send update for any updated children foreach (StageTransitionViewModel item in StageTransitions) { if (item.IsEdited == true) { item.Update(); } } // send update for any new children foreach (StageTransitionViewModel item in ItemsToAdd.OfType <StageTransitionViewModel>()) { item.Update(); StageTransitions.Add(item); } ItemsToAdd.Clear(); // send delete for any deleted children foreach (StageTransitionViewModel item in ItemsToDelete.OfType <StageTransitionViewModel>()) { item.Delete(); StageTransitions.Remove(item); } ItemsToDelete.Clear(); // reset modified for children foreach (StageTransitionViewModel item in StageTransitions) { item.ResetModified(false); } }
///-------------------------------------------------------------------------------- /// <summary>This method adds relationships for an entity to the view model.</summary> /// /// <param name="entity">The entity to add.</param> ///-------------------------------------------------------------------------------- public void AddRelationships(DiagramEntityViewModel diagramEntity) { NameObjectCollection relationshipsAdded = new NameObjectCollection(); // add relationships this entity is the source of foreach (Relationship relationship in diagramEntity.EntityViewModel.Entity.RelationshipList) { bool isDeletedRelationship = false; foreach (DiagramRelationshipViewModel diagramRelationship in ItemsToDelete.OfType <DiagramRelationshipViewModel>()) { if (diagramRelationship.RelationshipViewModel.Relationship.RelationshipID == relationship.RelationshipID) { isDeletedRelationship = true; break; } } if (isDeletedRelationship == false && relationshipsAdded[relationship.RelationshipID.ToString()] == null) { foreach (DiagramEntityViewModel loopEntity in DiagramEntities) { if (relationship.ReferencedEntityID == loopEntity.EntityViewModel.Entity.EntityID) { RelationshipViewModel relationshipViewModel = new RelationshipViewModel(relationship, Solution); AddRelationship(diagramEntity, loopEntity, relationshipViewModel); relationshipsAdded[relationship.RelationshipID.ToString()] = true; } } } } // add relationships this entity is the sink of foreach (DiagramEntityViewModel loopEntity in DiagramEntities) { foreach (Relationship relationship in loopEntity.EntityViewModel.Entity.RelationshipList) { if (relationship.ReferencedEntityID == diagramEntity.EntityViewModel.Entity.EntityID) { bool isDeletedRelationship = false; foreach (DiagramRelationshipViewModel diagramRelationship in ItemsToDelete.OfType <DiagramRelationshipViewModel>()) { if (diagramRelationship.RelationshipViewModel.Relationship.RelationshipID == relationship.RelationshipID) { isDeletedRelationship = true; break; } } if (isDeletedRelationship == false && relationshipsAdded[relationship.RelationshipID.ToString()] == null) { RelationshipViewModel relationshipViewModel = new RelationshipViewModel(relationship, Solution); AddRelationship(loopEntity, diagramEntity, relationshipViewModel); relationshipsAdded[relationship.RelationshipID.ToString()] = true; } } } } Refresh(false); }
///-------------------------------------------------------------------------------- /// <summary>This method adds a relationship to the view model.</summary> /// /// <param name="relationship">The relationship to add.</param> ///-------------------------------------------------------------------------------- public void DeleteRelationship(DiagramRelationshipViewModel relationship) { // remove diagram relationship from solution diagram RemoveRelationship(relationship); // add to deleted relationship list ItemsToDelete.Add(relationship); Refresh(false); }
///-------------------------------------------------------------------------------- /// <summary>This method deletes an entity from the view model and solution.</summary> /// /// <param name="entity">The entity to remove.</param> ///-------------------------------------------------------------------------------- public void DeleteEntity(DiagramEntityViewModel entity) { // remove diagram entity RemoveEntity(entity, true); // add to deleted entity list ItemsToDelete.Add(entity); Refresh(false); }
public AddsEditsDeletesSet( List <TItem> oldItems, List <TItem> newItems, Func <TItem, object> keySelector, Func <TItem, TItem, bool> itemsAreEqualComparer, Func <TItem, bool> itemCannotBeDeletedSelector = null) { OldItems = oldItems; NewItems = newItems; foreach (TItem newItem in newItems) { object newItemKey = keySelector(newItem); TItem matchingOldItem = oldItems.FirstOrDefault(oldItem => keySelector(oldItem).Equals(newItemKey)); if (matchingOldItem == null) { // No matching old item - this is a new item ItemsToAdd.Add(newItem); } else { // Found a matching old item if (itemsAreEqualComparer(newItem, matchingOldItem)) { // Items match - the item has not been changed ItemsWithNoChanges.Add(new OldAndNew <TItem> { Old = matchingOldItem, New = newItem }); } else { // Items don't match - there are changes ItemsToChange.Add(new OldAndNew <TItem> { Old = matchingOldItem, New = newItem }); } } } foreach (TItem oldItem in oldItems) { object oldItemKey = keySelector(oldItem); TItem matchingNewItem = newItems.FirstOrDefault(newItem => keySelector(newItem).Equals(oldItemKey)); if (matchingNewItem == null) { // No matching new item - this item has been deleted ItemsToDelete.Add(oldItem); } } if (itemCannotBeDeletedSelector != null) { ItemsThatCannotBeDeleted = ItemsToDelete.Where(itemCannotBeDeletedSelector).ToList(); } }
public void Save(ORM.Database database, bool updateAccount) { lock (Locker) { foreach (var item in Items.Where(item => Tokens == null || item.Value != Tokens).Where(item => !item.Value.IsTemporarily)) { if (item.Value.Record.IsNew) { database.Insert(item.Value.Record); item.Value.OnPersistantItemAdded(); item.Value.Record.IsNew = false; } else if (item.Value.Record.IsDirty) { database.Update(item.Value.Record); item.Value.OnPersistantItemUpdated(); } } foreach (var preset in Presets) { if (preset.IsNew) { database.Insert(preset); preset.IsNew = false; } else if (preset.IsDirty) { database.Update(preset); } } while (ItemsToDelete.Count > 0) { var item = ItemsToDelete.Dequeue(); database.Delete(item.Record); item.OnPersistantItemDeleted(); } while (PresetsToDelete.Count > 0) { var preset = PresetsToDelete.Dequeue(); database.Delete(preset); } Owner.WorldAccount.Tokens = Tokens == null ? 0 : (int)Tokens.Stack; if (updateAccount) { database.Update(Owner.WorldAccount); } } }
///-------------------------------------------------------------------------------- /// <summary>This method resets the items.</summary> ///-------------------------------------------------------------------------------- public void ResetItems() { if (ItemsToAdd.Count > 0) { foreach (WorkspaceViewModel item in ItemsToAdd) { Items.Remove(item); item.Dispose(); } ItemsToAdd.Clear(); } if (ItemsToDelete.Count > 0) { foreach (WorkspaceViewModel item in ItemsToDelete) { Items.Add(item); } ItemsToDelete.Clear(); } foreach (WorkspaceViewModel item in Items) { item.Reset(); } }
///-------------------------------------------------------------------------------- /// <summary>This method puts an item into the delete queue.</summary> /// /// <param name="item">The item to delete.</param> ///-------------------------------------------------------------------------------- public virtual void Delete(WorkspaceViewModel item) { ItemsToDelete.Add(item); Items.Remove(item); }
///-------------------------------------------------------------------------------- /// <summary>This method adds to PropertyInstance deletes.</summary> ///-------------------------------------------------------------------------------- public void AddToDeletedPropertyInstances(PropertyInstanceViewModel item) { ItemsToDelete.Add(item); Items.Remove(item); }
///-------------------------------------------------------------------------------- /// <summary>This method updates the view model data and sends update command back /// to the solution builder.</summary> ///-------------------------------------------------------------------------------- protected override void OnUpdate() { // set up reverse engineering instance if not present if (Feature.ReverseInstance == null && Feature.IsAutoUpdated == true) { Feature.ReverseInstance = new Feature(); Feature.ReverseInstance.TransformDataFromObject(Feature, null, false); // perform the update of EditFeature back to Feature Feature.TransformDataFromObject(EditFeature, null, false); Feature.IsAutoUpdated = false; } else if (Feature.ReverseInstance != null) { EditFeature.ResetModified(Feature.ReverseInstance.IsModified); if (EditFeature.Equals(Feature.ReverseInstance)) { // perform the update of EditFeature back to Feature Feature.TransformDataFromObject(EditFeature, null, false); Feature.IsAutoUpdated = true; } else { // perform the update of EditFeature back to Feature Feature.TransformDataFromObject(EditFeature, null, false); Feature.IsAutoUpdated = false; } } else { // perform the update of EditFeature back to Feature Feature.TransformDataFromObject(EditFeature, null, false); Feature.IsAutoUpdated = false; } Feature.ForwardInstance = null; if (FeatureNameCustomized || DescriptionCustomized || TagsCustomized) { Feature.ForwardInstance = new Feature(); Feature.ForwardInstance.FeatureID = EditFeature.FeatureID; Feature.SpecSourceName = Feature.DefaultSourceName; if (FeatureNameCustomized) { Feature.ForwardInstance.FeatureName = EditFeature.FeatureName; } if (DescriptionCustomized) { Feature.ForwardInstance.Description = EditFeature.Description; } if (TagsCustomized) { Feature.ForwardInstance.Tags = EditFeature.Tags; } } EditFeature.ResetModified(false); OnUpdated(this, null); // send update back to solution builder SendEditFeaturePerformed(); // send update for any updated Entities foreach (EntityViewModel item in Entities) { if (item.IsEdited == true) { item.Update(); } } // send update for any new Entities foreach (EntityViewModel item in ItemsToAdd.OfType <EntityViewModel>()) { item.Update(); Entities.Add(item); } // send delete for any deleted Entities foreach (EntityViewModel item in ItemsToDelete.OfType <EntityViewModel>()) { item.Delete(); Entities.Remove(item); } // reset modified for Entities foreach (EntityViewModel item in Entities) { item.ResetModified(false); } ItemsToAdd.Clear(); ItemsToDelete.Clear(); }
///-------------------------------------------------------------------------------- /// <summary>This method adds to Entity deletes.</summary> ///-------------------------------------------------------------------------------- public void AddToDeletedEntities(EntityViewModel item) { ItemsToDelete.Add(item); Items.Remove(item); }