Example #1
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)));
        }