private void BgwOnRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     if (e.Result is ImportedData fi)
     {
         Files      = new DocumentCollectionViewModel(fi.files);
         Recipients = new RecipientsSelectionViewModel(fi.recipients);
     }
 }
        public TransmittalViewModel(Transmittal transmittal)
        {
            OkayCommand           = new RelayCommand(OkayCommandExecute, OkayCommandCanExecute);
            CancelCommand         = new RelayCommand(CancelCommandExecute, CancelCommandCanExecute);
            AddFileCommand        = new RelayCommand(AddFileExecute, FileEditCanExecute);
            RemoveFileCommand     = new RelayCommand(RemoveFileExecute, FileRemoveCanExecute);
            EditRecipientsCommand = new RelayCommand(EditRecipientExecute, EditRecipientCanExecute);

            pg = new Progress <Document>(DocsUpdated);
            transmittalModel = transmittal;


            if (transmittalModel.IsLoadedFromDb)
            {
                Id = transmittalModel.Id;
                IssueToWorkshop = transmittalModel.IssueToWorkshop;

                SentDate          = transmittalModel.SentDate;
                IssueType         = transmittalModel.IssueType;
                TransmittalStatus = transmittalModel.TransmittalStatus;
                Comments          = transmittalModel.Comments;
                IssueBy           = transmittalModel.IssueBy;
                CreatedBy         = transmittalModel.CreatedBy;
                Project           = transmittalModel.Project;

                if (transmittalModel.ExtendedDataLoaded)
                {
                    transmittalModel.Files.ForEach(f => files.Add(new FileDataViewModel(f)));

                    Recipients = new RecipientsSelectionViewModel(transmittalModel.Recipients);
                }
            }
            else
            {
                CreatedBy         = transmittalModel.CreatedBy;
                TransmittalStatus = TransmittalStatus.Preparing;
            }


            if (!transmittalModel.IsLoadedFromDb)
            {
                ViewStatus &= ViewStatusTypes.LoadedDb;
            }
            if (User.ActiveUser.Group == Groups.NoPermisions)
            {
                ViewStatus &= ViewStatusTypes.ViewOnly;
            }
            if (TransmittalStatus == TransmittalStatus.Issued)
            {
                ViewStatus &= ViewStatusTypes.Approved;
            }

            if (!ViewStatus.HasFlag(ViewStatusTypes.ViewOnly) && !ViewStatus.HasFlag(ViewStatusTypes.Approved))
            {
                ViewStatus &= ViewStatusTypes.Editable;                                                                                                 //Otherwise it should be editable.
            }
        }