示例#1
0
        // id is actually permalink in this case
        public ActionResult Details(string id)
        {
            Post post;

            using (var context = new ApplicationDbContext())
            {
                post = context.Posts.Include("Comments").Single(p => p.Permalink == id);
            }

            var repository = new PostRepository();
            var recentPostLinks = repository.GetRecentPostLinks().Where(l => l.Permalink != id).ToArray();

            var model = new PostDetailsViewModel
                {
                    PostId = post.PostId,
                    Title = post.Title,
                    Permalink = post.Permalink,
                    CreationTime = post.DateCreated,
                    HtmlContent = post.HtmlContent,
                    Comments = post.Comments,
                    RecentPostLinks = recentPostLinks
                };

            return View(model);
        }
示例#2
0
        public ActionResult Index()
        {
            IEnumerable<Post> posts;

            using (var context = new ApplicationDbContext())
            {
                posts = context.Posts.Include("Comments").OrderByDescending(p => p.DateCreated).Take(5).ToArray();
            }

            var repository = new PostRepository();
            var recentPostLinks = repository.GetRecentPostLinks();

            var model = new HomeIndexViewModel { Posts = posts, RecentPostLinks = recentPostLinks };

            return View(model);
        }