Esempio n. 1
0
 public CategoryApiController(
     IAsyncOfmRepository <CategoryOfmForGet, int> asyncOfmRepository,
     IUrlHelper urlHelper,
     IHttpContextAccessor httpContextAccesor)
 {
     _asyncOfmRepository            = asyncOfmRepository;
     _shortCamelCasedControllerName = nameof(CategoryApiController).ToShortCamelCasedControllerName();
     _urlHelper             = urlHelper;
     _controllerGuardClause = new ControllerGuardClauses <CategoryOfmForGet, CategoryOfmForPost, CategoryOfmForPatch, int>(this);
     _hateoasLinkFactory    = new HateoasLinkFactory <int>(_urlHelper, nameof(CategoryApiController));
     _incomingHeaders       = Mapper.Map <IncomingHeaders>(httpContextAccesor.HttpContext.Items[nameof(IncomingRawHeaders)] as IncomingRawHeaders);
 }
        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);
        }