public async Task <IActionResult> DeleteAttachedFile(long id, long?fileId)
        {
            if (fileId == null)
            {
                return(JsonBadRequest("File ID is required."));
            }
            if (fileId.Value < 0)
            {
                return(JsonBadRequest("The file is locked. You can NOT delete the file."));
            }
            //存在チェック
            //子の添付ファイルが存在すれば親の学習履歴は必ず存在するはずなので、そっちはチェックしない
            TrainingHistoryAttachedFile file = await trainingHistoryRepository.GetAttachedFileAsync(fileId.Value);

            if (file == null)
            {
                return(JsonNotFound($"File ID {fileId.Value} is not found."));
            }

            trainingHistoryRepository.DeleteAttachedFile(file);
            await storageLogic.DeleteFileAsync(ResourceType.TrainingHistoryAttachedFiles, file.StoredPath);

            unitOfWork.Commit();

            return(JsonNoContent());
        }
        public async Task <IActionResult> DeleteFile(long?id, long?fileId, [FromServices] IDataSetRepository dataSetRepository)
        {
            if (id == null)
            {
                //IDが指定されていなければエラー
                return(JsonBadRequest("Invalid inputs."));
            }
            if (fileId == null)
            {
                return(JsonBadRequest("File ID is required."));
            }
            if (fileId.Value < 0)
            {
                return(JsonBadRequest("The file is locked. You can NOT delete the file."));
            }
            //Dataとそれに紐づくSectionimageをDBから取得
            var data = await dataRepository.GetDataIncludeAllAsync(id.Value);

            if (data == null)
            {
                return(JsonNotFound($"Data ID {id.Value} is not found."));
            }

            var checkResult = await CheckDataIsLocked(data, dataSetRepository);

            if (checkResult != null)
            {
                return(checkResult);
            }

            // ファイルの存在チェック
            var file = data.DataProperties.FirstOrDefault(d => d.Id == fileId);

            if (file == null)
            {
                return(JsonNotFound($"File ID {fileId.Value} is not found."));
            }

            // 削除処理
            dataRepository.DeleteFile(data, fileId.Value);
            await storageLogic.DeleteFileAsync(ResourceType.Data, file.DataFile.StoredPath);

            // 結果に関わらずコミット
            unitOfWork.Commit();

            return(JsonNoContent());
        }