public async Task SaveAttachmentAsync(DocumentContent attachment)
        {
            if (attachment == null || attachment.Content == null)
            {
                return;
            }

            var extension = Mapper.MapDocumentContentDataTypeEnumToExtension(attachment.DataType);

            var fileSavePicker = new FileSavePicker();

            fileSavePicker.FileTypeChoices.Add(extension + " Datei", new List <string> {
                "." + extension
            });
            fileSavePicker.DefaultFileExtension = "." + extension;

            fileSavePicker.SuggestedFileName = attachment.ProposedFilename;

            var fileToSave = await fileSavePicker.PickSaveFileAsync();

            if (null == fileToSave)
            {
                return;
            }

            try
            {
                using (var stream = await fileToSave.OpenStreamForWriteAsync())
                {
                    await stream.WriteAsync(attachment.Content, 0, attachment.Content.Length);

                    await stream.FlushAsync();

                    stream.Dispose();

                    Windows.System.Launcher.LaunchFileAsync(fileToSave);
                }
            }
            catch (Exception ex)
            {
                Log.Error("SaveAttachmentAsync", ex);
                ToastService.Display("Fehler", "Attachment konnte nicht gespeichert werden");
            }
        }
        public async Task SaveHtmlAsync()
        {
            var fileSavePicker = new FileSavePicker();

            fileSavePicker.FileTypeChoices.Add("Html Datei", new List <string> {
                ".html"
            });
            fileSavePicker.DefaultFileExtension = ".html";

            string dokumentNummer = CurrentDocument.Document.Dokumentnummer;

            fileSavePicker.SuggestedFileName = String.Format("Ris{0}.html", dokumentNummer);

            var fileToSave = await fileSavePicker.PickSaveFileAsync();

            if (null == fileToSave)
            {
                return;
            }

            try
            {
                using (var stream = await fileToSave.OpenStreamForWriteAsync())
                {
                    var writer = new StreamWriter(stream);
                    await writer.WriteAsync(SourceHtml);

                    await writer.FlushAsync();

                    writer.Dispose();
                }

                ToastService.Display("Dokument gespeichert",
                                     String.Format("\"{0}\" in \"{1}\" abgelegt", CurrentDocument.Document.Kurztitel, fileToSave.Name));
            }
            catch (Exception ex)
            {
                Log.Error("SaveHtmlAsync", ex);
                ToastService.Display("Fehler", "Dokument konnte nicht gespeichert werden");
            }
        }
        private async Task RefreshCachedDocumentAsync()
        {
            try
            {
                UpdateInProgress = true;

                // #1: Refresh the data
                string dokumentNummer = CurrentDocument.Document.Dokumentnummer;
                var    result         = await Task.Run(() => ParallelLoadSynced(dokumentNummer));

                if (null != result)
                {
                    CurrentDocument = result.Item1;
                    SourceHtml      = result.Item2;

                    // #2: Delete old row and Insert new one
                    var ctx = new RisDbContext();
                    var dl  = DbDownloadedDocumentFromViewModel(dokumentNummer);
                    await ctx.RefreshDownload(dl, CachedDocumentDatabaseId.Value);

                    CachedDocumentDatabaseId = dl.Id;

                    ToastService.Display("Aktualisierung erfolgreich", CurrentDocument.Document.Kurztitel);

                    return;
                }
            }
            catch (Exception ex)
            {
                Log.Error("RefreshCachedDocumentAsync", ex);
            }
            finally
            {
                UpdateInProgress = false;
            }

            ToastService.Display("Fehler",
                                 String.Format("Aktualisierung von \"{0}\" konnte nicht durchgeführt werden", CurrentDocument.Document.Kurztitel));
        }