///-------------------------------------------------------------------------------- /// <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 MethodViewModel PasteMethod(MethodViewModel copyItem, bool savePaste = true) { Method newItem = new Method(); newItem.ReverseInstance = new Method(); newItem.TransformDataFromObject(copyItem.Method, null, false); newItem.MethodID = Guid.NewGuid(); newItem.IsAutoUpdated = false; newItem.Entity = Entity; newItem.Solution = Solution; MethodViewModel newView = new MethodViewModel(newItem, Solution); newView.ResetModified(true); AddMethod(newView); // paste children foreach (ParameterViewModel childView in copyItem.Parameters) { newView.PasteParameter(childView, savePaste); } if (savePaste == true) { Solution.MethodList.Add(newItem); Entity.MethodList.Add(newItem); newView.OnUpdated(this, null); Solution.ResetModified(true); } return(newView); }
///-------------------------------------------------------------------------------- /// <summary>This method loads Methods 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 LoadMethods(Entity entity, Solution solution, bool loadChildren = true) { // attach the items Items.Clear(); if (Methods == null) { Methods = new EnterpriseDataObjectList <MethodViewModel>(); } if (loadChildren == true) { foreach (Method item in entity.MethodList) { MethodViewModel itemView = new MethodViewModel(item, solution); itemView.Updated += new EventHandler(Children_Updated); Methods.Add(itemView); Items.Add(itemView); } } }
///-------------------------------------------------------------------------------- /// <summary>This method applies method updates.</summary> ///-------------------------------------------------------------------------------- public void ProcessEditMethodPerformed(MethodEventArgs data) { try { bool isItemMatch = false; if (data != null && data.Method != null) { foreach (MethodViewModel item in Methods) { if (item.Method.MethodID == data.Method.MethodID) { isItemMatch = true; item.Method.TransformDataFromObject(data.Method, null, false); item.OnUpdated(item, null); item.ShowInTreeView(); break; } } if (isItemMatch == false) { // add new Method data.Method.Entity = Entity; MethodViewModel newItem = new MethodViewModel(data.Method, Solution); newItem.Updated += new EventHandler(Children_Updated); Methods.Add(newItem); Entity.MethodList.Add(newItem.Method); Solution.MethodList.Add(newItem.Method); Items.Add(newItem); OnUpdated(this, null); newItem.ShowInTreeView(); } } } catch (Exception ex) { ShowIssue(ex.Message + ex.StackTrace); } }
///-------------------------------------------------------------------------------- /// <summary>This method deletes an instance of Method from the view model.</summary> /// /// <param name="itemView">The Method to delete.</param> ///-------------------------------------------------------------------------------- public void DeleteMethod(MethodViewModel itemView) { itemView.Updated -= Children_Updated; Methods.Remove(itemView); Delete(itemView); }
///-------------------------------------------------------------------------------- /// <summary>This method adds an instance of Method to the view model.</summary> /// /// <param name="itemView">The Method to add.</param> ///-------------------------------------------------------------------------------- public void AddMethod(MethodViewModel itemView) { itemView.Updated += new EventHandler(Children_Updated); Methods.Add(itemView); Add(itemView); }