public async Task <ActionResult <ApiResponse> > GetEntityType(int id) { try { AppEntityType type = await _repo.GetEntityTypeByIdAsync(id); if (type == null) { return(NotFound(new ApiResponse(StatusCodes.Status404NotFound, "Erro. Tipo de entidade não encontrado."))); } AppEntityTypeModel typeModel = new AppEntityTypeModel() { Id = type.Id, Name = type.Name }; return(Ok(new ApiResponse <AppEntityTypeModel>(StatusCodes.Status200OK, "OK", typeModel))); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, new ApiResponse(StatusCodes.Status500InternalServerError, "Erro inesperado. Tente mais tarde."))); } }
public async Task <ActionResult <ApiResponse> > GetEntityTypes() { try { var types = await _repo.GetAllEntityTypesAsync(); var returnObj = new List <AppEntityTypeModel>(); foreach (var item in types) { var a = new AppEntityTypeModel() { Id = item.Id, Name = item.Name }; returnObj.Add(a); } return(Ok(new ApiResponse <List <AppEntityTypeModel> >(StatusCodes.Status200OK, "OK", returnObj))); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, new ApiResponse(StatusCodes.Status500InternalServerError, "Erro inesperado. Tente mais tarde."))); } }