public async Task <IActionResult> GetById(int id, WorkoutHistoryOfmResourceParameters workoutHistoryOfmResourceParameters) { var stringGuid = User.Claims.FirstOrDefault(c => c.Type == "sub")?.Value; if (String.IsNullOrWhiteSpace(stringGuid)) { return(Unauthorized()); } var ownerGuid = new Guid(stringGuid); var ofmForGetQueryResult = await _asyncOfmRepository.GetById(id, workoutHistoryOfmResourceParameters, ownerGuid); if (!_controllerGuardClause.ValidateGetById(ofmForGetQueryResult, id, out ObjectResult objectResult)) { return(objectResult); } var expandable = ofmForGetQueryResult.ReturnedTOfmForGet.ToExpandableOfm(); var shapedExpandable = expandable.Shape(workoutHistoryOfmResourceParameters.Fields); if (_incomingHeaders.IncludeHateoas) { shapedExpandable.Add("links", _hateoasLinkFactory.CreateLinksForOfmForGet(id, workoutHistoryOfmResourceParameters.Fields).ToList()); } return(Ok(shapedExpandable)); }
public async Task <IActionResult> GetById(int id, CategoryOfmResourceParameters categoryOfmResourceParameters) { var ofmForGetQueryResult = await _asyncOfmRepository.GetById(id, categoryOfmResourceParameters.Fields); if (!_controllerGuardClause.ValidateGetById(ofmForGetQueryResult, id, out ObjectResult objectResult)) { return(objectResult); } var expandable = ofmForGetQueryResult.ReturnedTOfmForGet.ToExpandableOfm(); var shapedExpandable = expandable.Shape(categoryOfmResourceParameters.Fields); if (_incomingHeaders.IncludeHateoas) { shapedExpandable.Add("links", _hateoasLinkFactory.CreateLinksForOfmForGet(id, categoryOfmResourceParameters.Fields).ToList()); } return(Ok(shapedExpandable)); }
public static IEnumerable <ExpandableOfmForGet> CreateHateoasForExpandableOfmForGets <TOfmForGet, TId>( this IEnumerable <ExpandableOfmForGet> expandableOfmForGetCollection, IUrlHelper urlhelper, string controllerName, string fields) where TOfmForGet : class where TId : struct { var hateoasLinkFactory = new HateoasLinkFactory <TId>(urlhelper, controllerName); var expandableOfmForGets = new List <ExpandableOfmForGet>(); foreach (var expandableOfmForGet in expandableOfmForGetCollection) { expandableOfmForGet.Add("links", hateoasLinkFactory.CreateLinksForOfmForGet((TId)expandableOfmForGet["Id"], fields).ToList()); expandableOfmForGets.Add(expandableOfmForGet); } return(expandableOfmForGets); }