private void ExecuteOne() { var component = ComponentEdit.NewComponentEdit(); component.PDNumber = CheckPDNumber(Path.GetFileNameWithoutExtension(FileName)); component.DownloadedTimestamp = DateTime.Now; component.Description = Description; component.PDStatus = SelectedPDStatus; component.ComponentType = SelectedComponentType; component.PDSource = SelectedPDSource; component.Xml = _xmlProvider.GetXmlStringService(XmlStream); var sourceComponent = ComponentEdit.GetComponent(component.PDNumber); if (!string.IsNullOrEmpty(sourceComponent.PDNumber)) { component.SourceComponentId = sourceComponent.ComponentId; } else { component.SourceComponentId = null; } component = component.Save(); _eventAggregator .GetEvent <ImportComponentCommand>() .Publish(component); }
public async Task <IActionResult> PutComponent(int id, ComponentEdit component) { if (id != component.Id) { return(BadRequest(new ResponseMessage("Request id and component id do not match!"))); } _bll.Components.UpdateNoReturnAsync(_componentMapper.MapToBLL(component)); await _bll.SaveChangesAsync(); return(NoContent()); }
public ComponentMinimal MapToBLL(ComponentEdit apiComponent) { return(new ComponentMinimal { Id = apiComponent.Id, ComponentTypeId = apiComponent.ComponentTypeId, ManufacturerId = apiComponent.ManufacturerId, Model = apiComponent.Model, ReleaseYear = apiComponent.ReleaseYear, ComponentName = apiComponent.ComponentName, Price = apiComponent.Price }); }
private void ReplaceComponent() { var component = ComponentEdit.GetComponent(UpdateComponentId); component.Description = Description; component.PDStatus = SelectedPDStatus; component.ComponentType = SelectedComponentType; component.PDSource = SelectedPDSource; component.Xml = _xmlProvider.GetXmlStringService(XmlStream); component = component.Save(); _eventAggregator .GetEvent <UpdateComponentCommand>() .Publish(component); }
public static object MakeSimpleDefaultEditor(object ob, System.Type t, string fname, object par) { string name = FriendlyString(fname); if (t == typeof(int)) { return(EditorGUILayout.IntField(name, (int)ob)); } else if (t == typeof(float)) { return(EditorGUILayout.FloatField(name, (float)ob)); } else if (t == typeof(bool)) { return(EditorGUILayout.Toggle(name, (bool)ob)); } else if (t == typeof(string)) { return(EditorGUILayout.TextField(name, (string)ob)); } else if (t == typeof(AnimationCurve)) { return(EditorGUILayout.CurveField(name, (AnimationCurve)ob)); } else if (t == typeof(Vector3)) { return(EditorGUILayout.Vector3Field(name, (Vector3)ob)); } else if (t == typeof(Vector2)) { return(EditorGUILayout.Vector2Field(name, (Vector2)ob)); } else if (t == typeof(Vector4)) { return(EditorGUILayout.Vector4Field(name, (Vector4)ob)); } else if (t == typeof(UnityEngine.GameObject)) { return(EditorGUILayout.ObjectField(name, (Object)ob, t, true)); } else if (t.IsSubclassOf(typeof(UnityEngine.Component))) { FieldInfo fedit = null; if (editorClass != null) { fedit = editorClass.GetField(t.ToString().ToLower() + "Edit"); } if (fedit == null) { return(EditorGUILayout.ObjectField(name, (Object)ob, t, true)); } else { List <ComponentEdit> a = fedit.GetValue(null) as List <ComponentEdit>; ComponentEdit ce = null; for (int i = 0; i < a.Count; i++) { if (a[i].com == ob) { ce = a[i]; break; } } if (ce == null) { ce = new ComponentEdit(); a.Add(ce); } EditorGUILayout.LabelField(name); EditorGUI.indentLevel++; EditorGUILayout.BeginHorizontal(); ob = EditorGUILayout.ObjectField((Object)ob, t, true, GUILayout.Width(150)); if (GUILayout.Button("New", GUILayout.Width(50))) { GameObject to = Selection.activeGameObject; GameObject g = GameObject.Find(t + "s"); if (g == null) { g = new GameObject(t + "s"); } GameObject go = new GameObject(to.name + "-" + par.GetType() + "-" + t); go.transform.parent = g.transform; go.transform.position = to.transform.position; ob = go.AddComponent(t); } if (GUILayout.Button("Sel", GUILayout.Width(50))) { Selection.activeGameObject = ((Component)ob).gameObject; } if (GUILayout.Button((ce.show?"De":"") + "Show", GUILayout.Width(70))) { ce.show = !ce.show; EditorUtility.SetDirty(ob as Object); } if (GUILayout.Button((ce.edit?"De":"") + "Edit", GUILayout.Width(70))) { ce.edit = !ce.edit; } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel--; return(ce.com = ob as Component); } } else if (t == typeof(LayerMask)) { return((LayerMask)(1 << EditorGUILayout.LayerField(name, ((LayerMask)ob).value))); } else if (t.IsArray) { System.Array a = (System.Array)ob; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(name, GUILayout.Width(100)); System.Type et = t.GetElementType(); FieldInfo ft = typeof(Util).GetField("type" + et.ToString(), BindingFlags.Public | BindingFlags.Static); FieldInfo fit = typeof(Util).GetField("it" + et.ToString(), BindingFlags.NonPublic | BindingFlags.Static); List <string> st = null; int it = -1; if (et.IsAbstract) { st = ft.GetValue(null) as List <string>; it = (int)fit.GetValue(null); it = EditorGUILayout.Popup(it, st.ToArray()); fit.SetValue(null, it); } FieldInfo fsoa = null; List <string> soa = null; if (typeof(ScriptableObject).IsAssignableFrom(et)) { fsoa = par.GetType().GetField(name + "Asset", BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase); soa = fsoa.GetValue(par) as List <string>; } if (GUILayout.Button("New", GUILayout.Width(50))) { System.Array ta = System.Array.CreateInstance(et, a.Length + 1); for (int i = 0; i < a.Length; i++) { ta.SetValue(a.GetValue(i), i); } object tob = null; System.Type eet = et; if (et.IsAbstract) { eet = typeof(Util).Assembly.GetType(st[it]); } if (typeof(ScriptableObject).IsAssignableFrom(eet)) { string sos = SOInstance(eet); tob = AssetDatabase.LoadAllAssetsAtPath(sos)[0]; soa.Add(sos); } else { tob = System.Activator.CreateInstance(eet); } ta.SetValue(tob, a.Length); return(ta); } if (GUILayout.Button("Clear", GUILayout.Width(50))) { System.Array ta = System.Array.CreateInstance(et, 0); if (soa != null) { foreach (string s in soa) { AssetDatabase.DeleteAsset(s); } soa.Clear(); } return(ta); } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel++; int oi = -1; foreach (object tob in a) { oi++; string ename = tob.GetType().ToString(); FieldInfo no = tob.GetType().GetField("name", BindingFlags.Instance | BindingFlags.Public); if (no != null) { ename = (string)no.GetValue(tob); } string efname = ename; ename = FriendlyString(ename); bool simple = (et.IsValueType || et == typeof(string) || et == typeof(UnityEngine.GameObject) || et == typeof(UnityEngine.Component)); bool bfo = true; EditorGUILayout.BeginHorizontal(); if (simple) { object tob1 = MakeSimpleDefaultEditor(tob, et, efname, ob); if (tob1 != null || !tob1.Equals(tob)) { if (et.IsSubclassOf(typeof(Object))) { Undo.RegisterUndo((Object)ob, ename); } a.SetValue(tob1, oi); } } else { string sename = ename; if (typeof(ScriptableObject).IsAssignableFrom(et)) { string ssoa = soa[oi]; ssoa = ssoa.Substring(ssoa.LastIndexOf("/") + 1); sename += "-" + ssoa; } FieldInfo fo = tob.GetType().GetField("foldout", BindingFlags.Instance | BindingFlags.Public); if (fo != null) { bfo = (bool)fo.GetValue(tob); bfo = EditorGUILayout.Foldout(bfo, sename); fo.SetValue(tob, bfo); } else { EditorGUILayout.LabelField(sename); } } if (GUILayout.Button("X", GUILayout.Width(30))) { System.Array ta = System.Array.CreateInstance(et, a.Length - 1); for (int i = 0, j = 0; i < a.Length; i++) { if (a.GetValue(i) != tob) { ta.SetValue(a.GetValue(i), j++); } } if (soa != null) { AssetDatabase.DeleteAsset(soa[oi]); soa.RemoveAt(oi); } return(ta); } EditorGUILayout.EndHorizontal(); if (!simple) { EditorGUI.indentLevel++; if (bfo) { MakeDefaultEditor(tob); } EditorGUI.indentLevel--; } } EditorGUI.indentLevel--; } return(ob); }