public async Task <IActionResult> Index(string slug = null)
        {
            var tutorials = (await wordPressService.GetPostsByCategory((int)PostCategory.Tutorials))?.OrderByDescending(o => o.Id);
            var firstSlug = tutorials?.Select(s => s.Slug).FirstOrDefault();

            if (string.IsNullOrEmpty(firstSlug))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (string.IsNullOrEmpty(slug))
            {
                return(RedirectToAction("Index", "Tutorial", new { slug = firstSlug }));
            }

            var id    = tutorials.Where(t => t.Slug == slug).Select(s => s.Id).Single();
            var model = new TutorialViewModel()
            {
                Tutorials = tutorials,
                Post      = await wordPressService.GetPost(id)
            };

            ViewBag.Title = model.Post.Title.Rendered;

            return(View(model));
        }
示例#2
0
        public async Task <IActionResult> Index()
        {
            var model = new NewsViewModel()
            {
                News = await wordPressService.GetPostsByCategory((int)PostCategory.News)
            };

            return(View(model));
        }