// // GET: /Admin/Links/ public ActionResult Index(int?page) { var links = ls.GetLinks(); var model = new Paginated <Links>(links, page ?? 1, 20); return(View(model)); }
public ActionResult Index() { //ViewBag.FirstNews = blogService.GetBlogs(10).Where(m => m.IsPublic == true).FirstOrDefault(); ViewBag.News = blogService.GetBlogs(18).Where(m => m.IsPublic == true).Take(10).ToList(); ViewBag.TeSe = blogService.GetBlogs(10).Where(m => m.IsPublic == true).Take(10).ToList(); ViewBag.TopCourse = blogService.GetBlogs(1).Where(m => m.IsPublic == true).Take(3).ToList(); ViewBag.Course = blogService.GetBlogs(1).Where(m => m.IsPublic == true).Skip(3).Take(7).ToList(); ViewBag.Links = ls.GetLinks().Where(m => m.IsEnable != "N").ToList(); return(View()); }
public override Task WriteAsync(OutputFormatterWriteContext context) { object data; if (context.Object is IEnumerable <object> list) { data = list.Select(o => new OutputObject(o) { Links = _linkService.GetLinks(o) }); } else { data = new OutputObject(context.Object) { Links = _linkService.GetLinks(context.Object) } }; return(base.WriteAsync(new OutputFormatterWriteContext(context.HttpContext, context.WriterFactory, typeof(OutputObject), data))); } }
public void OnInspectingResource(HalResourceInspectingContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Resource == null) { logger.LogDebug("Resource is null. Nothing to inspect."); return; } if (context.ActionContext == null) { throw new ArgumentException("ActionContext cannot be null.", nameof(context)); } if (!(context.ActionContext.ActionDescriptor is ControllerActionDescriptor descriptor)) { throw new HalException("Could not establish ControllerActionDescriptor reference."); } var links = linkService.GetLinks <HalLinkAttribute>(descriptor, context.ActionContext, context.OriginalObject); if (context.Resource.Links == null && links.Count > 0) { context.Resource.Links = new List <ILink>(); } foreach (var link in links) { var hlink = new Link(link.Rel, link.Uri); context.Resource.Links.Add(hlink); if (link.IsSingular) { if (context.Resource.SingularRelations == null) { context.Resource.SingularRelations = new HashSet <string>(); } if (!context.Resource.SingularRelations.Contains(link.Rel)) { context.Resource.SingularRelations.Add(link.Rel); } } } }
public async Task <Dictionary <string, int> > GetLinks() { return(await db.GetLinks()); }
public async Task <HalResourceInspectedContext> OnResourceInspectionAsync( HalResourceInspectingContext context, HalResourceInspectionDelegate next) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (next == null) { throw new ArgumentNullException(nameof(next)); } if (!context.IsRootResource) { throw new NotSupportedException("This inspector does not support embedded resources."); } if (context.Resource == null) { return(await next()); } if (context.ActionContext == null) { throw new ArgumentException("ActionContext cannot be null.", nameof(context)); } if (!(context.ActionContext.ActionDescriptor is ControllerActionDescriptor descriptor)) { throw new HalException("Could not establish ControllerActionDescriptor reference."); } if (context.ActionContext.HttpContext == null || context.ActionContext.HttpContext.Features == null) { throw new ArgumentException("HttpContext features cannot be null.", nameof(context)); } if (context.MvcPipeline == null) { throw new ArgumentException("Context does not contain the mvc pipeline.", nameof(context)); } var requestFeature = context.ActionContext.HttpContext.Features.Get <IHttpRequestFeature>(); var links = linkService.GetLinks <HalEmbedAttribute>(descriptor, context.ActionContext, context.OriginalObject); foreach (var link in links) { var halRequestFeature = new HalHttpRequestFeature(requestFeature) { Method = "GET", Path = link.Uri }; var halContext = new HalHttpContext(context.ActionContext.HttpContext, halRequestFeature); logger.LogDebug("About to invoke MVC pipeline with a GET request on path '{0}'.", link.Uri); await context.MvcPipeline.Pipeline(halContext); var response = halContext.Response as HalHttpResponse; if (response.StatusCode >= 200 && response.StatusCode <= 299) { logger.LogDebug("MVC pipeline returned success status code {0}. Invoking HAL resource factory.", response.StatusCode); IResource embedded = await context.EmbeddedResourcePipeline(response.ActionContext, response.Resource); embedded.Rel = link.Rel; if (embedded is IResourceCollection collection) { if (collection.Collection != null) { logger.LogDebug("Embedding collection of {0} resources to rel '{0}'", collection.Collection.Count, link.Rel); foreach (var item in collection.Collection) { item.Rel = link.Rel; context.Resource.Embedded.Add(item); } } } else { logger.LogDebug("Embedding resource to rel '{0}'", link.Rel); context.Resource.Embedded.Add(embedded); } } else { logger.LogWarning("MVC pipeline returned non-success status code {0}. Ignoring result.", response.StatusCode); } } var result = await next(); logger.LogTrace("After invoke next."); return(result); }