private void DisplayFolderTree()
        {
            try
            {
                LoadingData = true;

                DocumentFolderListResponse response;
                if (FolderFilterObject.Search_MultiLevel)
                {
                    response = new DocumentFolderSQLiteRepository().GetRootFolder(MainWindow.CurrentCompanyId);
                    if (response.Success)
                    {
                        DocumentTreeItems = new ObservableCollection <DocumentFolderViewModel>(response?.DocumentFolders ?? new List <DocumentFolderViewModel>());

                        if (DocumentTreeItems.Count() > 0)
                        {
                            SelectedTreeItem = DocumentTreeItems[0];
                            GetDirectoryTree(SelectedTreeItem);
                        }
                    }
                    else
                    {
                        MainWindow.ErrorMessage = response.Message;
                    }
                }
                else
                {
                    response = new DocumentFolderSQLiteRepository().GetDocumentFolders(MainWindow.CurrentCompanyId, FolderFilterObject);
                    if (response.Success)
                    {
                        DocumentTreeItems = new ObservableCollection <DocumentFolderViewModel>(response?.DocumentFolders ?? new List <DocumentFolderViewModel>());
                    }
                    else
                    {
                        MainWindow.ErrorMessage = response.Message;
                    }
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                LoadingData = false;
            }
        }
        void GetDirectoryTree(DocumentFolderViewModel parent)
        {
            List <DocumentFolderViewModel> directories;

            try
            {
                var response = new DocumentFolderSQLiteRepository().GetDocumentFolders(MainWindow.CurrentCompanyId, FolderFilterObject, false);

                directories = response?.DocumentFolders ?? new List <DocumentFolderViewModel>();
            }
            catch (Exception ex)
            {
                directories = new List <DocumentFolderViewModel>();
            }

            parent.SubDirectories = new ObservableCollection <DocumentFolderViewModel>(directories);
        }
Esempio n. 3
0
        private void btnSavePdf_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(DocumentName))
            {
                MainWindow.ErrorMessage = (string)Application.Current.FindResource("MorasUnetiNazivDokumentaUzicnik");
                return;
            }
            if (Images == null || Images.Where(x => x.IsSelected).Count() < 1)
            {
                MainWindow.ErrorMessage = (string)Application.Current.FindResource("MorasSkeniratiNestoIOznacitiStavkeUzvicnik");
                return;
            }
            if (String.IsNullOrEmpty(SelectedPath))
            {
                MainWindow.ErrorMessage = (string)Application.Current.FindResource("MorasOdabratiFolderUzvicnik");
                return;
            }
            CanInteractWithForm = false;
            Thread td = new Thread(() =>
            {
                try
                {
                    var tempPath = System.IO.Path.GetTempPath();

                    var generator = new PDFGenerator(Images
                                                     .Where(x => x.IsSelected)
                                                     .OrderBy(x => x.CreatedAt)
                                                     .Select(x => x.ImagePath)
                                                     .ToList(),
                                                     tempPath, DocumentName,
                                                     MainWindow.CurrentUser.FirstName + " " + MainWindow.CurrentUser.LastName);

                    CurrentDocumentFullPath = generator.Generate();

                    if (DocumentSavePathOption.Value == true)
                    {
                        File.Copy(CurrentDocumentFullPath, $"{SelectedPath}\\{DocumentName}.pdf");
                        Dispatcher.BeginInvoke((Action)(() => {
                            DocumentSaved?.Invoke(CurrentDocumentFullPath);
                        }));
                    }
                    else
                    {
                        var documentFolderResp = new DocumentFolderSQLiteRepository().GetDirectoryByPath(MainWindow.CurrentCompanyId, SelectedPath);
                        var documentFolder     = documentFolderResp?.DocumentFolder ?? null;


                        var azureClient = new AzureDataClient();



                        var file = azureClient.GetFile($"{SelectedPath}/{DocumentName}.pdf");
                        file.UploadFromFile(CurrentDocumentFullPath);

                        file.FetchAttributes();

                        var documentFile = new DocumentFileViewModel()
                        {
                            Identifier     = Guid.NewGuid(),
                            Name           = $"{DocumentName}.pdf",
                            DocumentFolder = documentFolder,
                            Path           = file.Uri.LocalPath,
                            Size           = file.Properties.Length / 1024,
                            CreatedAt      = file.Properties.LastModified.Value.DateTime,
                            Company        = new CompanyViewModel()
                            {
                                Id = MainWindow.CurrentCompanyId
                            },
                            CreatedBy = new UserViewModel()
                            {
                                Id = MainWindow.CurrentUserId
                            }
                        };

                        var documentFileService = DependencyResolver.Kernel.Get <IDocumentFileService>();

                        var response = documentFileService.Create(documentFile);
                        if (response.Success)
                        {
                            Dispatcher.BeginInvoke((Action)(() => {
                                DocumentSaved?.Invoke(file.Uri.LocalPath);
                            }));
                        }
                        else
                        {
                            MainWindow.WarningMessage = "Dokument je sačuvan na serveru ali nije indeksiran, molimo kontaktirajte administraciju!";
                            Dispatcher.BeginInvoke((Action)(() => {
                                DocumentSaved?.Invoke(file.Uri.LocalPath);
                            }));
                        }
                    }


                    MainWindow.SuccessMessage = (string)Application.Current.FindResource("DokumentJeUspesnoSacuvanUzvicnik");
                } catch (Exception ex)
                {
                    MainWindow.ErrorMessage = ex.Message;
                } finally
                {
                    CanInteractWithForm = true;
                }
            });

            td.IsBackground = true;
            td.Start();
        }