Esempio n. 1
0
        private void PoolingUpdate(object obj)
        {
            App.Current.Dispatcher.Invoke((Action) delegate // <--- HERE
            {
                try
                {
                    List <int> originalQids = Questions.Select(q => q.Id).ToList();
                    List <int> originalAids = Answers.Select(a => a.Id).ToList();

                    UpdateQuestionsList(QuestionSearchTxt);
                    if (SelectedAnswer != null)
                    {
                        Answer backup = new Answer();
                        backup.ShallowCopy(SelectedAnswer);
                        UpdateAnswersList(SelectedQuestion, AnswerSearchTxt);
                        OnPropertyChanged(nameof(SelectedQuestion));

                        SelectedAnswer.ShallowCopy(backup);
                        OnPropertyChanged(nameof(SelectedAnswer));

                        //thread safe way to get record updates pulled from database (doesn't do selected Q or A)
                        if (QandAMode == QandAMode.Answer)
                        {
                            if (Answers != null)
                            {
                                foreach (Answer a in Answers)
                                {
                                    if (a.Id != SelectedAnswer.Id)
                                    {
                                        UnitOfWork.Reload(a);
                                    }
                                }
                                OnPropertyChanged(nameof(AVisConDTO));
                            }
                        }
                        else
                        {
                            if (Questions != null)
                            {
                                foreach (Question q in Questions)
                                {
                                    if (q.Id != SelectedQuestion.Id)
                                    {
                                        UnitOfWork.Reload(q);
                                    }
                                }
                                OnPropertyChanged(nameof(AVisConDTO));
                            }
                        }
                    }
                    else
                    {
                        UpdateAnswersList(SelectedQuestion, AnswerSearchTxt);
                    }
                    List <int> newQIds = Questions.Select(q => q.Id).ToList();
                    List <int> newAIds = Answers.Select(a => a.Id).ToList();
                    SortNotifications(originalQids, originalAids, newQIds, newAIds);
                    UpdateCommentsList();
                }
                catch (Exception ex)
                {
                    ShowFeedback($"Error updating from database:\n{ex.Message}", FeedbackType.Error);
                }
            });
        }