public async Task <IActionResult> AddFile([FromForm] AddFileRequest request) { var userIdString = JWTUtility.GetUserId(User); if (userIdString == null) { return(BadRequest()); } var userId = int.Parse(userIdString); if (request.ParentFolder != null) { // Check if the parent folder does belong to the user if (!await _registerService.DoesFolderBelongToUser( userId, folderId: request.ParentFolder.Value)) { return(BadRequest()); } } // Check if the filename is valid if (!FileNameUtility.FileFolderNameIsValid(request.File.FileName)) { return(BadRequest(Texts.INVALID_FILE_NAME)); } // Check if the file does not exist if (await _registerService.DoesFileOrFolderAlreadyExist(userId, name: request.File.FileName, parentFolder: request.ParentFolder)) { return(BadRequest(Texts.FILE_FOLDER_ALREADY_EXISTS)); } var fileAdded = await _registerService.AddFile(userId, parentFolder : request.ParentFolder, request); if (fileAdded == null) { return(StatusCode(statusCode: 500, value: Texts.ERROR_SAVING_FILE)); } return(Ok(fileAdded)); }