///-------------------------------------------------------------------------------- /// <summary>This method is used to copy/paste a new item.</summary> /// /// <param name="copyItem">The item to copy/paste.</param> /// <param name="savePaste">Flag to determine whether to save the results of the paste.</param> ///-------------------------------------------------------------------------------- public CollectionViewModel PasteCollection(CollectionViewModel copyItem, bool savePaste = true) { Collection newItem = new Collection(); newItem.ReverseInstance = new Collection(); newItem.TransformDataFromObject(copyItem.Collection, null, false); newItem.PropertyID = Guid.NewGuid(); newItem.IsAutoUpdated = false; newItem.Entity = Entity; newItem.Solution = Solution; CollectionViewModel newView = new CollectionViewModel(newItem, Solution); newView.ResetModified(true); AddCollection(newView); // paste children if (savePaste == true) { Solution.CollectionList.Add(newItem); Entity.CollectionList.Add(newItem); newView.OnUpdated(this, null); Solution.ResetModified(true); } return(newView); }
///-------------------------------------------------------------------------------- /// <summary>This method loads Collections 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 LoadCollections(Entity entity, Solution solution, bool loadChildren = true) { // attach the items Items.Clear(); if (Collections == null) { Collections = new EnterpriseDataObjectList <CollectionViewModel>(); } if (loadChildren == true) { foreach (Collection item in entity.CollectionList) { CollectionViewModel itemView = new CollectionViewModel(item, solution); itemView.Updated += new EventHandler(Children_Updated); Collections.Add(itemView); Items.Add(itemView); } } }
///-------------------------------------------------------------------------------- /// <summary>This method applies collection updates.</summary> ///-------------------------------------------------------------------------------- public void ProcessEditCollectionPerformed(CollectionEventArgs data) { try { bool isItemMatch = false; if (data != null && data.Collection != null) { foreach (CollectionViewModel item in Collections) { if (item.Collection.PropertyID == data.Collection.PropertyID) { isItemMatch = true; item.Collection.TransformDataFromObject(data.Collection, null, false); item.OnUpdated(item, null); item.ShowInTreeView(); break; } } if (isItemMatch == false) { // add new Collection data.Collection.Entity = Entity; CollectionViewModel newItem = new CollectionViewModel(data.Collection, Solution); newItem.Updated += new EventHandler(Children_Updated); Collections.Add(newItem); Entity.CollectionList.Add(newItem.Collection); Solution.CollectionList.Add(newItem.Collection); Items.Add(newItem); OnUpdated(this, null); newItem.ShowInTreeView(); } } } catch (Exception ex) { ShowIssue(ex.Message + ex.StackTrace); } }
///-------------------------------------------------------------------------------- /// <summary>This method deletes an instance of Collection from the view model.</summary> /// /// <param name="itemView">The Collection to delete.</param> ///-------------------------------------------------------------------------------- public void DeleteCollection(CollectionViewModel itemView) { itemView.Updated -= Children_Updated; Collections.Remove(itemView); Delete(itemView); }
///-------------------------------------------------------------------------------- /// <summary>This method adds an instance of Collection to the view model.</summary> /// /// <param name="itemView">The Collection to add.</param> ///-------------------------------------------------------------------------------- public void AddCollection(CollectionViewModel itemView) { itemView.Updated += new EventHandler(Children_Updated); Collections.Add(itemView); Add(itemView); }