///-------------------------------------------------------------------------------- /// <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 ModelViewModel PasteModel(ModelViewModel copyItem, bool savePaste = true) { Model newItem = new Model(); newItem.ReverseInstance = new Model(); newItem.TransformDataFromObject(copyItem.Model, null, false); newItem.ModelID = Guid.NewGuid(); newItem.IsAutoUpdated = false; newItem.Solution = Solution; newItem.Solution = Solution; ModelViewModel newView = new ModelViewModel(newItem, Solution); newView.ResetModified(true); AddModel(newView); // paste children foreach (EnumerationViewModel childView in copyItem.EnumerationsFolder.Enumerations) { newView.EnumerationsFolder.PasteEnumeration(childView, savePaste); } foreach (ModelObjectViewModel childView in copyItem.ModelObjectsFolder.ModelObjects) { newView.ModelObjectsFolder.PasteModelObject(childView, savePaste); } if (savePaste == true) { Solution.ModelList.Add(newItem); newView.OnUpdated(this, null); Solution.ResetModified(true); } return(newView); }
///-------------------------------------------------------------------------------- /// <summary>This method loads Models into the view model.</summary> /// /// <param name="solution">The associated solution.</param> /// <param name="loadChildren">Flag indicating whether to perform a deeper load.</param> ///-------------------------------------------------------------------------------- public void LoadModels(Solution solution, bool loadChildren = true) { // attach the items Items.Clear(); if (Models == null) { Models = new EnterpriseDataObjectList <ModelViewModel>(); } if (loadChildren == true) { foreach (Model item in solution.ModelList) { ModelViewModel itemView = new ModelViewModel(item, solution); itemView.Updated += new EventHandler(Children_Updated); Models.Add(itemView); Items.Add(itemView); } } }
///-------------------------------------------------------------------------------- /// <summary>This method applies model updates.</summary> ///-------------------------------------------------------------------------------- public void ProcessEditModelPerformed(ModelEventArgs data) { try { bool isItemMatch = false; if (data != null && data.Model != null) { foreach (ModelViewModel item in Models) { if (item.Model.ModelID == data.Model.ModelID) { isItemMatch = true; item.Model.TransformDataFromObject(data.Model, null, false); item.OnUpdated(item, null); item.ShowInTreeView(); break; } } if (isItemMatch == false) { // add new Model data.Model.Solution = Solution; ModelViewModel newItem = new ModelViewModel(data.Model, Solution); newItem.Updated += new EventHandler(Children_Updated); Models.Add(newItem); Solution.ModelList.Add(newItem.Model); Items.Add(newItem); OnUpdated(this, null); newItem.ShowInTreeView(); } } } catch (Exception ex) { ShowIssue(ex.Message + ex.StackTrace); } }
///-------------------------------------------------------------------------------- /// <summary>This method deletes an instance of Model from the view model.</summary> /// /// <param name="itemView">The Model to delete.</param> ///-------------------------------------------------------------------------------- public void DeleteModel(ModelViewModel itemView) { itemView.Updated -= Children_Updated; Models.Remove(itemView); Delete(itemView); }
///-------------------------------------------------------------------------------- /// <summary>This method adds an instance of Model to the view model.</summary> /// /// <param name="itemView">The Model to add.</param> ///-------------------------------------------------------------------------------- public void AddModel(ModelViewModel itemView) { itemView.Updated += new EventHandler(Children_Updated); Models.Add(itemView); Add(itemView); }