public IActionResult CreateFolder(CreateFolderRequest request) { if (_folderRepo.Any(f => f.FolderName == request.NewFolderName && f.ParentFolderId == request.ParentFolderId)) { return(BadRequest("В текущей папке уже существует папка с таким именем")); } if (!_folderRepo.Any(f => request.ParentFolderId == f.Id) && request.ParentFolderId != Guid.Empty) { return(BadRequest("Папки с указанным id не существует!")); } if (request.ParentFolderId != Guid.Empty && !UserHasRole(request.ParentFolderId, AccessLevel.Create)) { return(BadRequest("Не достаточно уровня прав доступа!")); } var newFolder = new Folder { ParentFolderId = request.ParentFolderId, FolderName = request.NewFolderName }; DiskHelper.CreateFolder(_folderService.GetFullPath(request.ParentFolderId), request.NewFolderName); _db.Set <UsersFolders>().Add(new UsersFolders { AccessLevel = AccessLevel.Owner, User = UserContext, Folder = newFolder }); _db.Set <Folder>().Add(newFolder); _db.SaveChanges(); return(CreatedAtAction(nameof(GetFolder), routeValues: new { folderId = newFolder.Id }, newFolder.Id)); }