/// <summary>
        /// Tilføjer en bogføringslinje til regnskabet på baggrund af ViewModel til bogføring.
        /// </summary>
        /// <param name="viewModel">ViewModel, som er grundlaget for bogføringslinjen, der skal tilføjes.</param>
        protected override void Execute(IBogføringViewModel viewModel)
        {
            _isBusy = true;
            var task = _finansstyringRepository.BogførAsync(viewModel.Regnskab.Nummer, viewModel.Dato, viewModel.Bilag, viewModel.Kontonummer, viewModel.Tekst, viewModel.Budgetkontonummer, viewModel.Debit, viewModel.Kredit, viewModel.Adressekonto);

            ExecuteTask = task.ContinueWith(t =>
            {
                try
                {
                    HandleResultFromTask(t, viewModel, new object(), HandleResult);
                }
                finally
                {
                    _isBusy = false;
                }
            });
        }
Exemple #2
0
        /// <summary>
        /// Synchronize the locale accounting data for a given <see cref="IRegnskabModel"/> to the online accounting repository.
        /// </summary>
        /// <param name="accountingRepository">The <see cref="IFinansstyringRepository"/> for the online accounting repository.</param>
        /// <param name="localeDataStorage">The <see cref="ILocaleDataStorage"/> for storing locale data.</param>>
        /// <param name="syncDataDocument">The <see cref="XDocument"/> containing the locale accounting data.</param>
        /// <param name="accountingModel">The given <see cref="IRegnskabModel"/> on which to synchronize locale accounting data to the online repository.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="accountingRepository"/>, <paramref name="localeDataStorage"/>, <paramref name="syncDataDocument"/> or <paramref name="accountingModel"/> is null.</exception>
        private static async Task SyncLocaleData(IFinansstyringRepository accountingRepository, ILocaleDataStorage localeDataStorage, XDocument syncDataDocument, IRegnskabModel accountingModel)
        {
            if (accountingRepository == null)
            {
                throw new ArgumentNullException(nameof(accountingRepository));
            }
            if (localeDataStorage == null)
            {
                throw new ArgumentNullException(nameof(localeDataStorage));
            }
            if (syncDataDocument == null)
            {
                throw new ArgumentNullException(nameof(syncDataDocument));
            }
            if (accountingModel == null)
            {
                throw new ArgumentNullException(nameof(accountingModel));
            }

            try
            {
                XElement rootElement       = syncDataDocument.Root;
                XElement accountingElement = rootElement?.Elements(XName.Get("Regnskab", rootElement.Name.NamespaceName)).SingleOrDefault(element => GetAttributeValue(element, "nummer") != null && string.Compare(GetAttributeValue(element, "nummer"), accountingModel.Nummer.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal) == 0);
                if (accountingElement == null)
                {
                    return;
                }

                XElement postingLineToSync;
                lock (SyncRoot)
                {
                    postingLineToSync = GetPostingLineToSync(rootElement, accountingElement);
                    if (postingLineToSync != null && _cancelRequested == false)
                    {
                        postingLineToSync.StorePendingPostingLineInDocument();
                        localeDataStorage.StoreSyncDocument(syncDataDocument);
                    }
                }
                while (postingLineToSync != null && _cancelRequested == false)
                {
                    DateTime postingDate          = DateTime.ParseExact(GetAttributeValue(postingLineToSync, "dato"), "yyyyMMdd", CultureInfo.InvariantCulture);
                    string   voucherNo            = GetAttributeValue(postingLineToSync, "bilag");
                    string   accountNumber        = GetAttributeValue(postingLineToSync, "kontonummer");
                    string   text                 = GetAttributeValue(postingLineToSync, "tekst");
                    string   budgetAccountNumber  = GetAttributeValue(postingLineToSync, "budgetkontonummer");
                    decimal  debit                = GetAttributeValue(postingLineToSync, "debit") == null ? 0M : decimal.Parse(GetAttributeValue(postingLineToSync, "debit"), NumberStyles.Any, CultureInfo.InvariantCulture);
                    decimal  credit               = GetAttributeValue(postingLineToSync, "kredit") == null ? 0M : decimal.Parse(GetAttributeValue(postingLineToSync, "kredit"), NumberStyles.Any, CultureInfo.InvariantCulture);
                    int      addressAccountNumber = GetAttributeValue(postingLineToSync, "adressekonto") == null ? 0 : int.Parse(GetAttributeValue(postingLineToSync, "adressekonto"), NumberStyles.Integer, CultureInfo.InvariantCulture);
                    await accountingRepository.BogførAsync(accountingModel.Nummer, postingDate, voucherNo, accountNumber, text, budgetAccountNumber, debit, credit, addressAccountNumber);

                    lock (SyncRoot)
                    {
                        postingLineToSync.Remove();
                        localeDataStorage.StoreSyncDocument(syncDataDocument);

                        postingLineToSync = GetPostingLineToSync(rootElement, accountingElement);
                        if (postingLineToSync != null && _cancelRequested == false)
                        {
                            postingLineToSync.StorePendingPostingLineInDocument();
                            localeDataStorage.StoreSyncDocument(syncDataDocument);
                        }
                    }
                }
            }
            catch (IntranetGuiOfflineRepositoryException)
            {
                // We are currently offline.
                // Don't rethrow the exception.
            }
        }