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; } ToggleControls(false, Properties.OutputStrings.SavingEntityFormat1, _entityName); if (_entityId.HasValue && _entityId != Guid.Empty) { updateEntity.Id = _entityId.Value; if (_editingState == EditingState.Editing) { _iWriteToOutput.WriteToOutputEntityInstance(_service.ConnectionData, _entityName, _entityId.Value); } } 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.OutputStrings.SavingEntityCompletedFormat1, _entityName); this.Close(); } catch (Exception ex) { ToggleControls(true, Properties.OutputStrings.SavingEntityFailedFormat1, _entityName); _iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); } }
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.OutputStrings.SavingEntitiesFormat2, _entityName, _entityIds.Count); bool hasError = false; var saver = new EntitySaverFactory().GetEntitySaver(_entityName, _service); int number = 1; 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.OutputStrings.SavingEntityInstanceFormat4, number, _entityIds.Count, _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.OutputStrings.SavingEntityInstanceFailedFormat2, _entityName, id); } number++; } ToggleControls(true, Properties.OutputStrings.SavingEntitiesCompletedFormat2, _entityName, _entityIds.Count); if (!hasError) { this.Close(); } }