///-------------------------------------------------------------------------------- /// <summary>This method loads Properties 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 LoadProperties(Entity entity, Solution solution, bool loadChildren = true) { // attach the items Items.Clear(); if (Properties == null) { Properties = new EnterpriseDataObjectList <PropertyViewModel>(); } if (loadChildren == true) { foreach (Property item in entity.PropertyList) { PropertyViewModel itemView = new PropertyViewModel(item, solution); itemView.Updated += new EventHandler(Children_Updated); Properties.Add(itemView); Items.Add(itemView); } } }
///-------------------------------------------------------------------------------- /// <summary>This method applies property updates.</summary> ///-------------------------------------------------------------------------------- public void ProcessEditPropertyPerformed(PropertyEventArgs data) { try { bool isItemMatch = false; if (data != null && data.Property != null) { foreach (PropertyViewModel item in Properties) { if (item.Property.PropertyID == data.Property.PropertyID) { isItemMatch = true; item.Property.TransformDataFromObject(data.Property, null, false); item.OnUpdated(item, null); item.ShowInTreeView(); break; } } if (isItemMatch == false) { // add new Property data.Property.Entity = Entity; PropertyViewModel newItem = new PropertyViewModel(data.Property, Solution); newItem.Updated += new EventHandler(Children_Updated); Properties.Add(newItem); Entity.PropertyList.Add(newItem.Property); Solution.PropertyList.Add(newItem.Property); Items.Add(newItem); OnUpdated(this, null); newItem.ShowInTreeView(); } } } catch (Exception ex) { ShowIssue(ex.Message + ex.StackTrace); } }
///-------------------------------------------------------------------------------- /// <summary>This method deletes an instance of Property from the view model.</summary> /// /// <param name="itemView">The Property to delete.</param> ///-------------------------------------------------------------------------------- public void DeleteProperty(PropertyViewModel itemView) { itemView.Updated -= Children_Updated; Properties.Remove(itemView); Delete(itemView); }
///-------------------------------------------------------------------------------- /// <summary>This method adds an instance of Property to the view model.</summary> /// /// <param name="itemView">The Property to add.</param> ///-------------------------------------------------------------------------------- public void AddProperty(PropertyViewModel itemView) { itemView.Updated += new EventHandler(Children_Updated); Properties.Add(itemView); Add(itemView); }