/// <summary> /// Initializes a new instance of the <see cref="PartConnectorViewModel"/> class. /// </summary> public PartConnectorViewModel(PartConnector model) { Model = model; _partLinkMergeStrategy = new PartLinkMergeStrategy(); CopyFromModel(); }
public override void BeginEdit() { base.BeginEdit(); PartLinks.BeginEdit(); PartConnector.BeginEdit(); }
public override void CancelEdit() { // If single used, reset part link if (!PartConnector.IsCollection) { PartLink = PartConnector.PartLinks.FirstOrDefault(); } PartLink.CancelEdit(); PartConnector.CancelEdit(); base.CancelEdit(); }
public override void CancelEdit() { // Remove newly created part links PartLinks.RemoveRange(_newLinks); _newLinks.Clear(); // Add removed again PartLinks.AddRange(_removedLinks); _removedLinks.Clear(); // Cancel on existent PartLinks.CancelEdit(); PartConnector.CancelEdit(); base.CancelEdit(); }
public override void EndEdit() { // End on part links PartLinks.EndEdit(); // Add new links var newLinks = _newLinks.Select(n => n.PartLink); PartConnector.PartLinks.AddRange(newLinks); _newLinks.Clear(); // Remove removed links from connector PartConnector.PartLinks.RemoveRange(_removedLinks.Select(l => l.PartLink)); _removedLinks.Clear(); PartConnector.EndEdit(); base.EndEdit(); }
private async Task ChangeLink(object obj) { var dialog = PartDialogsFactory.CreateSelectPartDialog(PartConnector); await DialogManager.ShowDialogAsync(dialog); if (!dialog.Result) { PartDialogsFactory.Destroy(dialog); return; } var partLink = PartConnector.CreatePartLink(dialog.SelectedProduct); if (!PartConnector.IsCollection) { PartConnector.PartLinks.Clear(); } PartConnector.PartLinks.Add(partLink); PartLink = partLink; }
private void ConvertParts(IProductType productType, IEnumerable <PropertyInfo> properties, ProductModel converted) { var connectors = new List <PartConnector>(); foreach (var property in properties) { var displayName = property.GetDisplayName(); if (typeof(IProductPartLink).IsAssignableFrom(property.PropertyType)) { var link = (IProductPartLink)property.GetValue(productType); var partModel = ConvertPart(link); var connector = new PartConnector { Name = property.Name, DisplayName = displayName, Type = FetchProductType(property.PropertyType), Parts = partModel is null ? new PartModel[0] : new[] { partModel }, PropertyTemplates = EntryConvert.EncodeClass(property.PropertyType, ProductSerialization) }; connectors.Add(connector); } else if (typeof(IEnumerable <IProductPartLink>).IsAssignableFrom(property.PropertyType)) { var links = (IEnumerable <IProductPartLink>)property.GetValue(productType); var linkType = property.PropertyType.GetGenericArguments()[0]; var connector = new PartConnector { IsCollection = true, Name = property.Name, DisplayName = displayName, Type = FetchProductType(linkType), Parts = links?.Select(ConvertPart).ToArray(), PropertyTemplates = EntryConvert.EncodeClass(linkType, ProductSerialization) }; connectors.Add(connector); } } converted.Parts = connectors.ToArray(); }
public override void EndEdit() { PartLink.EndEdit(); PartConnector.EndEdit(); base.EndEdit(); }
/// <summary> /// Updates the model /// </summary> public void UpdateModel(PartConnector model) { Model = model; CopyFromModel(); }