public static section GetSection(Constants.Section section) { using (var context = new SlackerNewsEntities()) { return(context.sections.SingleOrDefault(t => t.id == (int)section)); } }
public static List <article> GetArticles(Constants.Section section, int numArticles = 15, Grouping groupBy = Grouping.ThisWeek) { using (var context = new SlackerNewsEntities()) { DateTime start = StartForGrouping(groupBy); DateTime end = EndForGrouping(groupBy); return(context.articles .Where(t => t.create_datetime > start && t.create_datetime < end && t.section_id == (int)section) .OrderByDescending(t => t.score) .Take(numArticles) // .OrderByDescending(t => t.create_datetime) .ToList()); } }
public ActionResult Section(Constants.Section section, Repository.Grouping groupBy = Repository.Grouping.ThisWeek) { var sectionEntry = Repository.GetSection(section); if (sectionEntry == null) { return(HttpNotFound()); } ViewBag.SectionName = sectionEntry.name; SetNavLinks(); // @TODO: replace with more scalable method ViewBag.SectionId = (int)section; ViewBag.GroupBy = groupBy; var articles = Repository.GetArticles(section, 15, groupBy); return(View(articles)); }
public static void AddCustomRoute(this RouteCollection routes, string routeText, Constants.Section section) { string routeName = "sections/" + routeText; routes.MapRoute( name: routeName, url: routeName, defaults: new { Controller = "Home", action = "Section", section = (int)section }); }