Exemplo n.º 1
0
        public async Task <ActionResult <EntityModel[]> > Get(int rasaNluId, int rasaNluDataId, int exampleId)
        {
            try
            {
                var result = await _repository.GetEntitiesByExampleIdAsync(rasaNluId, rasaNluDataId, exampleId);

                return(_mapper.Map <EntityModel[]>(result));
            } catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }
        }
        public async Task <IActionResult> Delete(int rasaNluId, int rasaNluDataId, int exampleId)
        {
            try
            {
                var commonExample = await _repository.GetExampleByRasaNluIdAsync(rasaNluId, rasaNluDataId, exampleId);

                if (commonExample == null)
                {
                    return(NotFound($"Failed to find the example with Id: {exampleId}"));
                }

                var entities = await _repository.GetEntitiesByExampleIdAsync(rasaNluId, rasaNluDataId, exampleId);

                // Delete the CommonExample
                _repository.Delete(commonExample);

                if (entities != null)
                {
                    foreach (var entity in entities)
                    {
                        // Delete all the entities that are related to commonExample
                        _repository.Delete(entity);
                    }
                }

                if (await _repository.SaveChangesAsync())
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest($"Failed to Delte the Common Example with Id: {exampleId}"));
                }
            } catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }
        }