public async Task <ActionResult <CommonExampleModel> > Put(int rasaNluId, int rasaNluDataId, int exampleId, CommonExampleModel model) { try { var oldExample = await _repository.GetExampleByRasaNluIdAsync(rasaNluId, rasaNluDataId, exampleId); if (oldExample == null) { return(NotFound($"Could not find example with Id: {exampleId}")); } _mapper.Map(model, oldExample); if (await _repository.SaveChangesAsync()) { return(_mapper.Map <CommonExampleModel>(oldExample)); } else { return(BadRequest("Failed To Update the old Common Example")); } } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } }
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")); } }