public async Task <IActionResult> GetFamilyById(int id, [FromQuery] bool includeLinks = true, [FromQuery] bool includeMammals = false) { try { var result = await _familyRepository.GetFamilyById(id, includeMammals); if (result == null) { throw new System.Exception($"Cant find family with id: {id}"); } var mappedResult = _mapper.Map <FamilyDTO>(result); if (includeLinks) { mappedResult.Mammals = mappedResult.Mammals.Select(m => HateoasMainLinks(m)).ToList(); return(Ok(HateoasMainLinks(mappedResult))); } return(Ok(mappedResult)); } catch (TimeoutException e) { return(this.StatusCode(StatusCodes.Status408RequestTimeout, $"Request timeout: {e.Message}")); } catch (Exception e) { return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e.Message}")); } }
public ValidationError Execute(Child child, NonBlockingValidationContext context) { if (child.FamilyId.HasValue) { var family = child.Family ?? _families.GetFamilyById(child.FamilyId.Value); ValidateSubObject(family, child); if (family.ValidationErrors.Count > 0) { return(new ValidationError( field: "Family", message: "Family has validation errors", isSubObjectValidation: true )); } } return(null); }