コード例 #1
0
        public async Task <ActionResult <EntityModel> > Post(int rasaNluId, int rasaNluDataId,
                                                             int exampleId, EntityModel model)
        {
            try
            {
                var commonExample = await _repository.GetExampleByRasaNluIdAsync(rasaNluId, rasaNluDataId, exampleId);

                if (commonExample == null)
                {
                    return(NotFound($"Could Not find example with Id: {exampleId}"));
                }

                var entity = _mapper.Map <Entity>(model);
                entity.CommonExample = commonExample;

                _repository.Add(entity);

                if (await _repository.SaveChangesAsync())
                {
                    var url = _linkGenerator.GetPathByAction(HttpContext,
                                                             "Get",
                                                             values: new { rasaNluId, rasaNluDataId, exampleId, id = entity.Id });
                    return(Created(url, _mapper.Map <EntityModel>(entity)));
                }
                else
                {
                    return(BadRequest("Failed To save the new Entity"));
                }
            } catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }
        }
コード例 #2
0
        public async Task <ActionResult <CommonExampleModel> > Post(int rasaNluId, int rasaNluDataId, CommonExampleModel model)
        {
            try
            {
                var rasaNluData = await _repository.GetRasaNluDataByNluModelAsync(rasaNluId, rasaNluDataId);

                if (rasaNluData == null)
                {
                    return(NotFound("The NLU Data does not Exist"));
                }

                var commonExample = _mapper.Map <CommonExample>(model);
                commonExample.RasaNLUData = rasaNluData;

                _repository.Add(commonExample);

                if (await _repository.SaveChangesAsync())
                {
                    var url = _linkGenerator.GetPathByAction(HttpContext,
                                                             "Get",
                                                             values: new { rasaNluId, rasaNluDataId, id = commonExample.Id });
                    return(Created(url, _mapper.Map <CommonExampleModel>(commonExample)));
                }
                else
                {
                    return(BadRequest("Failed To save the new Common Example"));
                }
            } catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }
        }