public DeleteCore DeleteEntity(Type clazz, int id, IUnitOfWork uow = null, Action beforeDeletion = null)
        {
            var deletion = new DeleteCore(configuration, uow);

            deletion.BeforeDeletion = beforeDeletion;

            #region Подготовка удаления

            IPage <PrepareDeletionViewModel> preparePage = null;

            using (var cancellation = new CancellationTokenSource()) {
                try
                {
                    preparePage = navigation.OpenViewModel <PrepareDeletionViewModel, DeleteCore, CancellationTokenSource>(null, deletion, cancellation);
                    deletion.PrepareDeletion(clazz, id, cancellation.Token);
                    if (cancellation.IsCancellationRequested)
                    {
                        deletion.Close();
                        return(deletion);
                    }
                }
                finally
                {
                    if (preparePage != null)
                    {
                        navigation.ForceClosePage(preparePage, CloseSource.External);
                    }
                }
            }

            #endregion

            #region Диалог удаления
            if (deletion.TotalLinks > 0)
            {
                var deletionPage = navigation.OpenViewModel <DeletionViewModel, DeleteCore>(null, deletion);
                deletionPage.ViewModel.DeletionAccepted = () => RunDeletion(deletion);
                deletionPage.PageClosed += delegate(object sender, PageClosedEventArgs e) {
                    if (e.CloseSource != CloseSource.Self)
                    {
                        deletion.Close();
                    }
                };
            }
            else if (interactive.Question($"Удалить {deletion.RootEntity.Title}?"))
            {
                RunDeletion(deletion);
            }
            else
            {
                deletion.Close();
                deletion.DeletionExecuted = false;
            }
            #endregion
            return(deletion);
        }
Пример #2
0
 private void RunDeletion(DeleteCore deletion)
 {
     using (var cancellation = new CancellationTokenSource()) {
         var progressPage = navigation.OpenViewModel <DeletionProcessViewModel, DeleteCore, CancellationTokenSource>(null, deletion, cancellation);
         deletion.RunDeletion(cancellation.Token);
         if (cancellation.IsCancellationRequested)
         {
             deletion.Close();
             return;
         }
         navigation.ForceClosePage(progressPage, CloseSource.External);
         deletion.Close();
     }
 }