Ejemplo n.º 1
0
        // this method return path to current folder as list
        public Stack <FolderShortInfoVM> GetFolderPath(string currFolderId, string userId)
        {
            Stack <FolderShortInfoVM> folderPath = new Stack <FolderShortInfoVM>();

            bool rootFolder = false;

            do
            {
                Folder folder = _database.GetRepository <Folder>().Get(currFolderId);
                if (folder == null)
                {
                    throw new StatusCodeException("Unable to define folder path.", StatusCodes.Status500InternalServerError);
                }

                FolderVM vm = new FolderVM {
                    IsShared = folder.IsShared, OwnerId = folder.OwnerId
                };
                if (CheckAccessToView(vm, userId) || HasSharedChildren(currFolderId))
                {
                    FolderShortInfoVM folderInfo = new FolderShortInfoVM {
                        Id = folder.Id, Name = ElementHelperClass.DefineFileName(folder.Path)
                    };
                    currFolderId = folder.ParentFolderId;
                    if (folder.ParentFolderId == null)
                    {
                        rootFolder      = true;
                        folderInfo.Name = "Your drive";
                    }
                    folderPath.Push(folderInfo);
                }
                else
                {
                    rootFolder = true;
                }
            } while (!rootFolder);

            return(folderPath);
        }
Ejemplo n.º 2
0
        // this method returns file by id
        public FileVM GetFileById(string id)
        {
            FileVM file = _mapper.Map <DAL.Entities.File, FileVM>(_database.GetRepository <DAL.Entities.File>().Get(id));

            if (file == null)
            {
                throw new StatusCodeException($"The file with ID = {id} doesn't exists.", StatusCodes.Status404NotFound);
            }

            file.OwnerId = _database.GetRepository <Folder>().Get(file.FolderId).OwnerId;
            file.Name    = ElementHelperClass.DefineFileName(file.Path);

            var    provider = new FileExtensionContentTypeProvider();
            string contentType;

            if (!provider.TryGetContentType(file.Name, out contentType))
            {
                contentType = "application/octet-stream";
            }
            file.ContentType = contentType;

            return(file);
        }