private async void btnSaveEntity_Click(object sender, RoutedEventArgs e) { var updateEntity = new Entity(_entityName); var list = _listAttributeControls.OfType <IAttributeMetadataControl <AttributeMetadata> >().ToList(); foreach (var item in list) { item.AddChangedAttribute(updateEntity); } if (!updateEntity.Attributes.Any()) { _iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.NoChangesInEntityFormat1, _entityName); _iWriteToOutput.ActivateOutputWindow(_service.ConnectionData); return; } if (_entityId != Guid.Empty) { updateEntity.Id = _entityId; } ToggleControls(false, Properties.WindowStatusStrings.SavingEntityFormat1, _entityName); if (_entityInstance != null) { _iWriteToOutput.WriteToOutputEntityInstance(_service.ConnectionData, _entityInstance); } try { var saver = new EntitySaverFactory().GetEntitySaver(_entityName, _service); var tempEntityId = await saver.UpsertAsync(updateEntity, (s) => UpdateStatus(s)); _iWriteToOutput.WriteToOutputEntityInstance(_service.ConnectionData, _entityName, tempEntityId); ToggleControls(true, Properties.WindowStatusStrings.SavingEntityCompletedFormat1, _entityName); this.Close(); } catch (Exception ex) { ToggleControls(true, Properties.WindowStatusStrings.SavingEntityFailedFormat1, _entityName); _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); } }
private async Task PerformDeleteEntity(string folder, Guid idPluginType, string name) { string message = string.Format(Properties.MessageBoxStrings.AreYouSureDeleteSdkObjectFormat2, PluginType.EntityLogicalName, name); if (MessageBox.Show(message, Properties.MessageBoxStrings.QuestionTitle, MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK) { var service = await GetService(); ToggleControls(service.ConnectionData, false, Properties.WindowStatusStrings.DeletingEntitiesFormat2, service.ConnectionData.Name, PluginType.EntityLogicalName); try { _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.DeletingEntity); _iWriteToOutput.WriteToOutputEntityInstance(service.ConnectionData, PluginType.EntityLogicalName, idPluginType); await service.DeleteAsync(PluginType.EntityLogicalName, idPluginType); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); _iWriteToOutput.ActivateOutputWindow(service.ConnectionData); } ToggleControls(service.ConnectionData, true, Properties.WindowStatusStrings.DeletingEntitiesCompletedFormat2, service.ConnectionData.Name, PluginType.EntityLogicalName); ShowExistingPluginTypes(); } }
private async void btnTransferEntities_Click(object sender, RoutedEventArgs e) { if (!IsControlsEnabled) { return; } if (_entityMetadata == null || !_entityCollection.Any() ) { return; } ToggleControls(false, Properties.WindowStatusStrings.SavingEntitiesFormat1, _entityMetadata.LogicalName); bool hasError = false; foreach (var entity in _entityCollection) { var updateEntity = new Entity(_entityMetadata.LogicalName) { Id = entity.Id, }; foreach (var attribute in entity.Attributes) { if (attribute.Value != null) { if (attribute.Value is EntityReference entityReference && _dictLookupMapping.ContainsKey(entityReference) ) { updateEntity.Attributes[attribute.Key] = _dictLookupMapping[entityReference].CurrentValue; } else { updateEntity.Attributes[attribute.Key] = attribute.Value; } } } try { _iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.WindowStatusStrings.SavingEntityInstanceFormat2, _entityMetadata.LogicalName, entity.Id); _iWriteToOutput.WriteToOutputEntityInstance(_service.ConnectionData, updateEntity); await _service.UpsertAsync(updateEntity); } catch (Exception ex) { hasError = true; _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex, Properties.WindowStatusStrings.SavingEntityInstanceFailedFormat2, _entityMetadata.LogicalName, entity.Id); } }
private async void btnSaveEntity_Click(object sender, RoutedEventArgs e) { if (!_entityIds.Any()) { return; } var list = _listAttributeControls.OfType <IAttributeMetadataControl <AttributeMetadata> >().ToList(); { var testEntity = new Entity(_entityName); foreach (var item in list) { item.AddChangedAttribute(testEntity); } if (!testEntity.Attributes.Any()) { _iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.NoChangesInEntityFormat1, _entityName); _iWriteToOutput.ActivateOutputWindow(_service.ConnectionData); return; } } ToggleControls(false, Properties.WindowStatusStrings.SavingEntitiesFormat1, _entityName); bool hasError = false; var saver = new EntitySaverFactory().GetEntitySaver(_entityName, _service); foreach (var id in _entityIds) { var updateEntity = new Entity(_entityName) { Id = id, }; foreach (var item in list) { item.AddChangedAttribute(updateEntity); } try { _iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.WindowStatusStrings.SavingEntityInstanceFormat2, _entityName, id); _iWriteToOutput.WriteToOutputEntityInstance(_service.ConnectionData, updateEntity); await saver.UpsertAsync(updateEntity, (s) => UpdateStatus(s)); } catch (Exception ex) { hasError = true; _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex, Properties.WindowStatusStrings.SavingEntityInstanceFailedFormat2, _entityName, id); } } ToggleControls(true, Properties.WindowStatusStrings.SavingEntitiesCompletedFormat1, _entityName); if (!hasError) { this.Close(); } }