public async Task <ActionResult <FileItem> > EditShareFile(Guid uuid, [FromBody] EditFileSystemItemShareBody body)
        {
            try
            {
                await ValidateFileSystemItemShare(body);
            }
            catch (HttpResultException exc)
            {
                return(exc.Result);
            }

            if (await dbContext.ShareFiles.AnyAsync(f =>
                                                    f.Uuid != uuid && f.Name == body.Name && f.UserId == body.UserId))
            {
                return(BadRequest("File with this name is already shared"));
            }

            ShareFile shareFile = await dbContext.ShareFiles
                                  .Include(f => f.Permission)
                                  .FirstOrDefaultAsync(f => f.Uuid == uuid);

            if (shareFile == null)
            {
                return(NotFound("Share file not found"));
            }

            shareFile.Name     = body.Name;
            shareFile.IsListed = body.IsListed;
            shareFile.UserId   = string.IsNullOrWhiteSpace(body.UserId) ? null : body.UserId;

            await dbContext.SaveChangesAsync();

            return(shareFile.ToFileItem());
        }
        public async Task <ActionResult <FileItem> > AddShareFile([FromBody] AddFileShareBody body)
        {
            InternalFile file;

            try
            {
                file = await ValidateAddFileShare(body);
            }
            catch (HttpResultException exc)
            {
                return(exc.Result);
            }

            if (await dbContext.ShareFiles.AnyAsync(f => f.Name == body.Name && f.UserId == body.UserId))
            {
                return(BadRequest("File with this name is already shared"));
            }

            ShareFile shareFile = new ShareFile()
            {
                Name       = body.Name,
                Path       = file.PhysicalPath,
                IsListed   = body.IsListed,
                UserId     = string.IsNullOrWhiteSpace(body.UserId) ? null : body.UserId,
                Permission = Models.FileItemPermission.New(body.Permission),
            };

            await dbContext.ShareFiles.AddAsync(shareFile);

            await dbContext.SaveChangesAsync();

            return(shareFile.ToFileItem());
        }