public JsonResult Create([FromBody] DocumentFolderViewModel c)
        {
            DocumentFolderResponse response = new DocumentFolderResponse();

            try
            {
                response = documentFolderService.Create(c);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
                Console.WriteLine(ex.Message);
            }

            return(Json(response, new Newtonsoft.Json.JsonSerializerSettings()
            {
                Formatting = Newtonsoft.Json.Formatting.Indented
            }));
        }
        private async void btnCreateFolder_Click(object sender, RoutedEventArgs e)
        {
            var result = await GetNewFolderName();

            NewFolderName = result;

            if (String.IsNullOrEmpty(NewFolderName))
            {
                MessageBox.Show("Naziv foldera ne moze biti prazan!");
                return;
            }

            string basePath = SelectedTreeItem?.Path;

            if (String.IsNullOrEmpty(basePath))
            {
                MessageBox.Show("Bazna putanja ne moze biti prazna!");
                return;
            }

            try
            {
                var parent = azureClient.GetDirectory(basePath);
                if (!parent.Exists())
                {
                    throw new Exception("Odabrani folder ne postoji!");
                }

                var childFolder = parent.GetDirectoryReference(NewFolderName);
                if (childFolder.Exists())
                {
                    throw new Exception("Folder sa zadatim imenom već postoji!");
                }

                childFolder.Create();

                var newDir = new DocumentFolderViewModel()
                {
                    Identifier   = Guid.NewGuid(),
                    ParentFolder = SelectedTreeItem,
                    Name         = NewFolderName,
                    Path         = childFolder.Uri.LocalPath,
                    CreatedAt    = DateTime.Now,
                    UpdatedAt    = DateTime.Now,
                    Company      = new ServiceInterfaces.ViewModels.Common.Companies.CompanyViewModel()
                    {
                        Id = MainWindow.CurrentCompanyId
                    },
                    CreatedBy = new ServiceInterfaces.ViewModels.Common.Identity.UserViewModel()
                    {
                        Id = MainWindow.CurrentUserId
                    }
                };

                var response = documentFolderService.Create(newDir);
                if (response.Success)
                {
                    newDir.Id = response?.DocumentFolder?.Id ?? 0;
                    new DocumentFolderSQLiteRepository().Sync(documentFolderService, ((done, toDo) => {
                        Debug.WriteLine($"Syncing folders: {done} out of {toDo}");
                    }));
                    SelectedTreeItem.SubDirectories.Add(newDir);
                    SelectedTreeItem.IsDirExpanded = true;
                    MainWindow.SuccessMessage      = "Folder je uspešno kreiran!";
                }
            }
            catch (Exception ex)
            {
                MainWindow.ErrorMessage = ex.Message;
            }

            NewFolderName = "";
        }
Esempio n. 3
0
        public void GetDocumentFolders(IDocumentFolderService service, IDocumentFileService fileService, DocumentFolderViewModel dir, bool recursive = false)
        {
            if (CancelOperation)
            {
                return;
            }

            if (dir != null)
            {
                CloudFileDirectory dirPath = GetDirectory(dir.Path);
                if (dirPath != null && dirPath.Exists())
                {
                    currentlyIndexedNumber++;
                    IndexingDirectoryChanged?.Invoke(dir.Path, currentlyIndexedNumber);

                    if (dir.Id < 1)
                    {
                        var response = service.Create(dir);
                        if (response.Success)
                        {
                            dir.Id = response?.DocumentFolder?.Id ?? 0;
                        }
                        else
                        {
                            dir.Id = -1;
                        }
                    }
                    if (dir.Id > 0)
                    {
                        dirPath.FetchAttributes();
                        var subFilesAndDirectories = dirPath.ListFilesAndDirectories();

                        var subFiles = subFilesAndDirectories.OfType <CloudFile>()
                                       .Select(x => new DocumentFileViewModel()
                        {
                            Identifier     = Guid.NewGuid(),
                            DocumentFolder = dir,
                            Name           = x.Name,
                            Path           = x.Uri.LocalPath,

                            Company = new ServiceInterfaces.ViewModels.Common.Companies.CompanyViewModel()
                            {
                                Id = MainWindow.CurrentCompanyId
                            },
                            CreatedBy = new ServiceInterfaces.ViewModels.Common.Identity.UserViewModel()
                            {
                                Id = MainWindow.CurrentUserId
                            }
                        })
                                       .ToList();
                        subFiles.ForEach(x => GetDocumentAttributes(x));

                        var fileResponse = fileService.SubmitList(subFiles);



                        var subDirectories = subFilesAndDirectories.OfType <CloudFileDirectory>()
                                             .Select(x => new DocumentFolderViewModel()
                        {
                            Path    = x.Uri.LocalPath, Name = x.Name, Identifier = Guid.NewGuid(), ParentFolder = dir,
                            Company = new ServiceInterfaces.ViewModels.Common.Companies.CompanyViewModel()
                            {
                                Id = MainWindow.CurrentCompanyId
                            },
                            CreatedBy = new ServiceInterfaces.ViewModels.Common.Identity.UserViewModel()
                            {
                                Id = MainWindow.CurrentUserId
                            }
                        })
                                             .ToList();

                        var response = service.SubmitList(subDirectories);
                        if (response.Success)
                        {
                            dir.SubDirectories = new ObservableCollection <DocumentFolderViewModel>(response?.DocumentFolders ?? new List <DocumentFolderViewModel>());

                            if (recursive)
                            {
                                foreach (var item in dir.SubDirectories)
                                {
                                    if (CancelOperation)
                                    {
                                        return;
                                    }

                                    GetDocumentFolders(service, fileService, item, recursive);
                                }
                            }
                        }
                    }
                }
            }
        }