コード例 #1
0
        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."));
            }
            //存在チェック
            //子の添付ファイルが存在すれば親の推論履歴は必ず存在するはずなので、そっちはチェックしない
            InferenceHistoryAttachedFile file = await inferenceHistoryRepository.GetAttachedFileAsync(fileId.Value);

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

            inferenceHistoryRepository.DeleteAttachedFile(file);
            await storageLogic.DeleteFileAsync(ResourceType.InferenceHistoryAttachedFiles, file.StoredPath);

            unitOfWork.Commit();

            return(JsonNoContent());
        }
コード例 #2
0
        public async Task <IActionResult> RegistAttachedFile(long id, [FromBody] AddFileInputModel model)
        {
            //データの入力チェック
            if (!ModelState.IsValid)
            {
                return(JsonBadRequest("Invalid inputs."));
            }

            //データの存在チェック
            var inferenceHistory = await inferenceHistoryRepository.GetByIdAsync(id);

            if (inferenceHistory == null)
            {
                return(JsonNotFound($"Inference ID {id} is not found."));
            }

            //同じ名前のファイルは登録できない
            if (await inferenceHistoryRepository.ExistsAttachedFileAsync(id, model.FileName))
            {
                return(JsonConflict($"Inference {id} has already a file named {model.FileName}."));
            }

            var attachedFile = new InferenceHistoryAttachedFile
            {
                InferenceHistoryId = id,
                FileName           = model.FileName,
                Key        = ResourceType.InferenceHistoryAttachedFiles.ToString(), //model.Key ?? ResourceType.InferenceHistoryAttachedFiles.ToString();
                StoredPath = model.StoredPath
            };

            inferenceHistoryRepository.AddAttachedFile(attachedFile);
            unitOfWork.Commit();

            return(JsonOK(new AttachedFileOutputModel(id, model.FileName, attachedFile.Id)));
        }
コード例 #3
0
 /// <summary>
 /// 指定した推論履歴添付ファイルを削除します。
 /// </summary>
 /// <param name="file">削除対象のファイル</param>
 public void DeleteAttachedFile(InferenceHistoryAttachedFile file)
 {
     DeleteModel <InferenceHistoryAttachedFile>(file);
 }
コード例 #4
0
 /// <summary>
 /// 推論履歴添付ファイルを追加します。
 /// </summary>
 /// <param name="file">追加対象のファイル</param>
 public void AddAttachedFile(InferenceHistoryAttachedFile file)
 {
     AddModel <InferenceHistoryAttachedFile>(file);
 }