Esempio n. 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"));
            }
        }
        public async Task <ActionResult <CommonExampleModel> > Get(int rasaNluId, int rasaNluDataId, int exampleId)
        {
            try
            {
                var result = await _repository.GetExampleByRasaNluIdAsync(rasaNluId, rasaNluDataId, exampleId);

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

                return(_mapper.Map <CommonExampleModel>(result));
            } catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }
        }