///-------------------------------------------------------------------------------- /// <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); } }
///-------------------------------------------------------------------------------- /// <summary>This method disposes of resources in the view model.</summary> ///-------------------------------------------------------------------------------- protected override void OnDispose() { if (EntityReferences != null) { foreach (EntityReferenceViewModel itemView in EntityReferences) { itemView.Updated -= Children_Updated; itemView.Dispose(); } EntityReferences.Clear(); EntityReferences = null; } Entity = null; base.OnDispose(); }
private void SetInitialValue() { if (EntityReference != null && EntityReferences != null) { var current = EntityReferences.FirstOrDefault(k => k.Id == EntityReference.Id); if (current != null) { CurrentEntityReference = current; } else { _view.RaiseValueChangedEvent(null); } } }
///-------------------------------------------------------------------------------- /// <summary>This method loads EntityReferences into the view model.</summary> /// /// <param name="entity">The entity to load.</param> /// <param name="solution">The associated solution.</param> /// <param name="loadChildren">Flag indicating whether to perform a deeper load.</param> ///-------------------------------------------------------------------------------- public void LoadEntityReferences(Entity entity, Solution solution, bool loadChildren = true) { // attach the items Items.Clear(); if (EntityReferences == null) { EntityReferences = new EnterpriseDataObjectList <EntityReferenceViewModel>(); } if (loadChildren == true) { foreach (EntityReference item in entity.EntityReferenceList) { EntityReferenceViewModel itemView = new EntityReferenceViewModel(item, solution); itemView.Updated += new EventHandler(Children_Updated); EntityReferences.Add(itemView); Items.Add(itemView); } } }
///-------------------------------------------------------------------------------- /// <summary>This method applies entityreference deletes.</summary> ///-------------------------------------------------------------------------------- public void ProcessDeleteEntityReferencePerformed(EntityReferenceEventArgs data) { try { bool isItemMatch = false; if (data != null && data.EntityReference != null) { foreach (EntityReferenceViewModel item in EntityReferences.ToList <EntityReferenceViewModel>()) { if (item.EntityReference.PropertyID == data.EntityReference.PropertyID) { // remove item from tabs, if present WorkspaceEventArgs message = new WorkspaceEventArgs(); message.ItemID = item.EntityReference.PropertyID; Mediator.NotifyColleagues <WorkspaceEventArgs>(MediatorMessages.Command_CloseItemRequested, message); // delete children for (int i = item.Items.Count - 1; i >= 0; i--) { } // delete item isItemMatch = true; EntityReferences.Remove(item); Entity.EntityReferenceList.Remove(item.EntityReference); Items.Remove(item); Entity.ResetModified(true); OnUpdated(this, null); break; } } if (isItemMatch == false) { ShowIssue(DisplayValues.Issue_DeleteItemNotFound); } } } catch (Exception ex) { ShowIssue(ex.Message + ex.StackTrace); } }
///-------------------------------------------------------------------------------- /// <summary>This method applies entityreference updates.</summary> ///-------------------------------------------------------------------------------- public void ProcessEditEntityReferencePerformed(EntityReferenceEventArgs data) { try { bool isItemMatch = false; if (data != null && data.EntityReference != null) { foreach (EntityReferenceViewModel item in EntityReferences) { if (item.EntityReference.PropertyID == data.EntityReference.PropertyID) { isItemMatch = true; item.EntityReference.TransformDataFromObject(data.EntityReference, null, false); item.OnUpdated(item, null); item.ShowInTreeView(); break; } } if (isItemMatch == false) { // add new EntityReference data.EntityReference.Entity = Entity; EntityReferenceViewModel newItem = new EntityReferenceViewModel(data.EntityReference, Solution); newItem.Updated += new EventHandler(Children_Updated); EntityReferences.Add(newItem); Entity.EntityReferenceList.Add(newItem.EntityReference); Solution.EntityReferenceList.Add(newItem.EntityReference); Items.Add(newItem); OnUpdated(this, null); newItem.ShowInTreeView(); } } } catch (Exception ex) { ShowIssue(ex.Message + ex.StackTrace); } }
///-------------------------------------------------------------------------------- /// <summary>This method deletes an instance of EntityReference from the view model.</summary> /// /// <param name="itemView">The EntityReference to delete.</param> ///-------------------------------------------------------------------------------- public void DeleteEntityReference(EntityReferenceViewModel itemView) { itemView.Updated -= Children_Updated; EntityReferences.Remove(itemView); Delete(itemView); }
///-------------------------------------------------------------------------------- /// <summary>This method adds an instance of EntityReference to the view model.</summary> /// /// <param name="itemView">The EntityReference to add.</param> ///-------------------------------------------------------------------------------- public void AddEntityReference(EntityReferenceViewModel itemView) { itemView.Updated += new EventHandler(Children_Updated); EntityReferences.Add(itemView); Add(itemView); }
public override EntityComponent ConstructComponent(Entity master, EntityReferences references) { return(ConstructComponent <EntityBeingNet, EntityBeingNetData>(master, references, this)); }