/// <summary> /// Deletes selected component instance /// </summary> /// <param name="t"></param> private void DeleteComponent(Component t) { if (t.GetType() == typeof(Computer)) { var c = ComputerCollection.Where(f => f.Pc == t).Single(); ComputerCollection.Remove(c); } else { List <ComputerItem> tmp = ComputerCollection.Where(i => i.Fields.Where(f => f.fieldInfo.FieldType == t.GetType()).Count() != 0).ToList(); tmp.ForEach(i => i.Fields.Where(f => f.fieldInfo.FieldType == t.GetType()).ToList().ForEach(f => { f.fieldInfo.SetValue(i.Pc, null); f.fieldValue = null; })); var a = ComputerCollection; ComputerCollection = null; ComputerCollection = a; } ComponentCollection.Remove(t); }
/// <summary> /// Updates component instance from user input /// </summary> /// <param name="t"></param> private void UpdateComponent(Component t) { int index = 0; if (t is Computer) //Required to find match in computer collection because it might be impossible to find it after update call { index = ComputerCollection.IndexOf(ComputerCollection.Single(i => i.Pc == t)); } t.Update(SelectedComponentFieldsList.Select(field => field.fieldValue).ToArray()); SelectedComponentType = null; SelectedComponentType = t.GetType(); SelectedComponentInstance = t; List <ComputerItem> tmp = ComputerCollection.Where(i => i.Fields.Where(f => f.fieldInfo.FieldType == t.GetType()).Count() != 0).ToList(); tmp.ForEach(i => i.Fields.Where(f => f.fieldInfo.FieldType == t.GetType()).ToList().ForEach(f => { f.fieldInfo.SetValue(i.Pc, t); f.fieldValue = t; })); if (t is Computer) { ComputerCollection[index] = new ComputerItem(t as Computer, SelectedComponentFieldsList); } var a = ComputerCollection; ComputerCollection = null; ComputerCollection = a; }