public async Task <IActionResult> Delete(long?id, [FromServices] IPreprocessHistoryRepository preprocessHistoryRepository)
        {
            //データの入力チェック
            if (id == null)
            {
                return(JsonBadRequest("Invalid inputs."));
            }
            //データの存在チェック
            var preprocessing = await preprocessRepository.GetByIdAsync(id.Value);

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

            var history = preprocessHistoryRepository.Find(p => p.PreprocessId == id.Value);

            if (history != null)
            {
                //過去に前処理を実行済みなので、削除できない
                return(JsonConflict($"Preprocessing ID {id.Value} is already executed. History ID = {history.Id} "));
            }

            preprocessRepository.Delete(preprocessing);
            unitOfWork.Commit();

            return(JsonNoContent());
        }
        /// <summary>
        /// 前処理履歴作成の入力モデルのチェックを行う。
        /// </summary>
        private async Task <Result <PreprocessHistory, IActionResult> > ValidateCreatePreprocessHistoryInputModelAsync(long preprocessId, long?inputDataId, IDataRepository dataRepository)
        {
            if (inputDataId == null)
            {
                return(Result <PreprocessHistory, IActionResult> .CreateErrorResult(JsonBadRequest("Data ID is requried.")));
            }

            if (!ModelState.IsValid)
            {
                return(Result <PreprocessHistory, IActionResult> .CreateErrorResult(JsonBadRequest("Invalid Input")));
            }

            // データIDの存在確認
            var data = await dataRepository.GetByIdAsync(inputDataId.Value);

            if (data == null)
            {
                return(Result <PreprocessHistory, IActionResult> .CreateErrorResult(JsonNotFound($"Data ID {inputDataId} is not found.")));
            }

            // 前処理の存在確認
            var preprocess = await preprocessRepository.GetByIdAsync(preprocessId);

            if (preprocess == null)
            {
                return(Result <PreprocessHistory, IActionResult> .CreateErrorResult(JsonNotFound($"Preprocessing ID {preprocessId} is not found.")));
            }

            // 実行コマンドが指定されていない前処理は起動不能(空白だけでもアウト)
            if (string.IsNullOrWhiteSpace(preprocess.EntryPoint))
            {
                return(Result <PreprocessHistory, IActionResult> .CreateErrorResult(JsonNotFound($"Preprocessing {preprocess.Name} can not be run because of lack of an execution command.")));
            }
            // イメージが指定されていない前処理は起動不能
            if (string.IsNullOrEmpty(preprocess.ContainerImage) || string.IsNullOrEmpty(preprocess.ContainerTag))
            {
                return(Result <PreprocessHistory, IActionResult> .CreateErrorResult(JsonNotFound($"Preprocessing {preprocess.Name} can not be run because a container image has not been selected properly yet.")));
            }

            //前処理が既に実行中か確認する
            var preprocessHistory = preprocessHistoryRepository.Find(pph => pph.InputDataId == inputDataId && pph.PreprocessId == preprocess.Id);

            if (preprocessHistory != null)
            {
                string status = ContainerStatus.Convert(preprocessHistory.Status).Name;
                return(Result <PreprocessHistory, IActionResult> .CreateErrorResult(JsonNotFound($"Data {data.Id}:{data.Name} has already been processed by {preprocess.Id}:{preprocess.Name}. Status:{status}")));
            }

            preprocessHistory = new PreprocessHistory()
            {
                InputDataId  = data.Id,
                PreprocessId = preprocess.Id,
                Preprocess   = preprocess,
                Status       = ContainerStatus.Running.Key
            };

            return(Result <PreprocessHistory, IActionResult> .CreateResult(preprocessHistory));
        }
        public async Task <IActionResult> EditDetails(long?id, [FromBody] CreateInputModel model)
        {
            // データの入力チェック
            if (!ModelState.IsValid || !id.HasValue)
            {
                return(JsonBadRequest("Invalid inputs."));
            }
            if (model.GitModel != null && model.GitModel.IsValid() == false)
            {
                return(JsonBadRequest($"The input about Git is not valid."));
            }

            // データの存在チェック
            var preprocessing = await preprocessRepository.GetIncludeAllAsync(id.Value);

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

            var history = preprocessHistoryRepository.Find(p => p.PreprocessId == id.Value);

            if (history != null)
            {
                // 過去に前処理を実行済みなので、編集できない
                return(JsonConflict($"Preprocessing ID {id.Value} is already executed. History ID = {history.Id} "));
            }

            var errorResult = await SetPreprocessDetailsAsync(preprocessing, model);

            if (errorResult != null)
            {
                return(errorResult);
            }
            unitOfWork.Commit();

            return(JsonOK(new IndexOutputModel(preprocessing)));
        }
        public async Task <IActionResult> EditDetails(long?id, [FromBody] CreateInputModel model, [FromServices] IPreprocessHistoryRepository preprocessHistoryRepository)
        {
            //データの入力チェック
            if (!ModelState.IsValid || !id.HasValue)
            {
                return(JsonBadRequest("Invalid inputs."));
            }
            if (model.GitModel != null && model.GitModel.IsValid() == false)
            {
                return(JsonBadRequest($"The input about Git is not valid."));
            }

            //データの存在チェック
            var preprocessing = await preprocessRepository.GetIncludeAllAsync(id.Value);

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

            var history = preprocessHistoryRepository.Find(p => p.PreprocessId == id.Value);

            if (history != null)
            {
                //過去に前処理を実行済みなので、編集できない
                return(JsonConflict($"Preprocessing ID {id.Value} is already executed. History ID = {history.Id} "));
            }

            var errorResult = await SetPreprocessDetailsAsync(preprocessing, model);

            if (errorResult != null)
            {
                return(errorResult);
            }
            unitOfWork.Commit();

            var result = new DetailsOutputModel(preprocessing);

            //Gitの表示用URLを作る
            if (preprocessing.RepositoryGitId != null)
            {
                result.GitModel.Url = gitLogic.GetTreeUiUrl(preprocessing.RepositoryGitId.Value, preprocessing.RepositoryName, preprocessing.RepositoryOwner, preprocessing.RepositoryCommitId);
            }

            return(JsonOK(result));
        }