Exemplo n.º 1
0
        /// <summary>
        /// Add given relationship to diagrram
        /// </summary>
        /// <param name="relationship">Relationship</param>
        /// <param name="canvas">Canvas for relationship add</param>
        /// <returns>Task for async execution</returns>
        public async Task AddRelationship(RelationshipModel relationship, DesignerCanvas canvas)
        {
            ConnectionInfoViewModel vm = new ConnectionInfoViewModel();

            vm.DesignerCanvas       = canvas;
            vm.RelationshipModel    = relationship;
            vm.SourceViewModel      = ViewModel.TableViewModels.FirstOrDefault(t => t.Model.Equals(relationship.Source));
            vm.DestinationViewModel = ViewModel.TableViewModels.FirstOrDefault(t => t.Model.Equals(relationship.Destination));
            await vm.BuildConnection3(ViewModel);

            ViewModel.ConnectionInfoViewModels.Add(vm);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create new
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Confirm_OnExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var isOk = await CheckIntegrity();

            if (isOk)
            {
                var relModel = new RelationshipModel
                {
                    Name        = RelationshipName,
                    Source      = SourceTableVm.Model,
                    Destination = DestinationTableVm.Model
                };
                relModel.Attributes.AddRange(GridData);
                relModel.Optionality = relModel.Attributes.All(t => t.Destination.AllowNull)
                                ? Optionality.Optional
                                : Optionality.Mandatory;
                relModel.DeleteAction = OnDeleteComboBox.SelectedValue as string;
                relModel.UpdateAction = OnUpdateComboBox.SelectedValue as string;

                var    updater = new DatabaseUpdater();
                string res     = updater.AddRelationship(relModel);

                if (res != null)
                {
                    await this.ShowMessageAsync("Add foreign key", res);
                }
                else
                {
                    ConnectionInfoViewModel model = new ConnectionInfoViewModel()
                    {
                        DestinationViewModel = DestinationTableVm,
                        SourceViewModel      = SourceTableVm,
                        DesignerCanvas       = Canvas
                    };
                    model.RelationshipModel.RefreshModel(relModel);
                    await model.BuildConnection3(DesignerViewModel);

                    DesignerViewModel.ConnectionInfoViewModels.Add(model);
                    DialogResult = true;
                    Close();
                }
            }
        }