public Entities.Storage.Directory RetrieveUploadDirectory()
        {
            return(this.cachingService.GetOrSet("UploadDirectory", () =>
            {
                using (var ctx = dbContextFactory.Create())
                {
                    var directoryDbSet = ctx.Set <Entities.Storage.Directory>();
                    var locationDbSet = ctx.Set <Entities.Storage.Location>();

                    var directory = directoryDbSet.Include(x => x.Location).FirstOrDefault(x => x.Id == UPLOAD_STRING);

                    if (directory == null)
                    {
                        var location = locationDbSet.FirstOrDefault(x => x.Id == UPLOAD_STRING);

                        if (location == null)
                        {
                            var settings = settingsService.Get();

                            location = new Entities.Storage.Location
                            {
                                Id = UPLOAD_STRING,
                                Volume = UPLOAD_STRING,
                                RPath = settings.DocumentsPath
                            };

                            locationDbSet.Add(location);
                        }

                        directory = new Entities.Storage.Directory
                        {
                            Id = UPLOAD_STRING,
                            LocationId = UPLOAD_STRING,
                            Name = "ALL",
                            Location = location
                        };

                        directoryDbSet.Add(directory);

                        ctx.SaveChanges();
                    }

                    return directory;
                }
            }));
        }
        private string GetDirectoryPath(Entities.Storage.Directory directory, Entities.Storage.Location location)
        {
            var settings = settingsService.Get();

            return(Path.Combine(location.RPath ?? settings.DocumentsPath, location.Volume, directory.Name));
        }
        public FileResult GenerateUniqueFilePath(Entities.Storage.Directory directory, Entities.Storage.Location location, string fileExtension)
        {
            var fullDirPath = this.GetDirectoryPath(directory, location);

            string filePath = string.Empty;

            do
            {
                filePath = Path.Combine(fullDirPath, Guid.NewGuid().ToString() + fileExtension);
            }while (File.Exists(filePath));

            return(new FileResult
            {
                AbsolutePath = filePath,
                OdissDirectory = directory
            });
        }