Exemplo n.º 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);
        }
Exemplo n.º 2
0
        private static void MapPropertiesFromDatabase()
        {
            using (var context = new ApplicationDbContext())
            {
                var settings = context.BlogSettings;
                var keys = settings.Select(s => s.Key).ToArray();

                foreach (var key in keys)
                {
                    typeof(BlogSettings).GetProperty(key, BindingFlags.Public | BindingFlags.Static)
                        .SetValue(null, settings.Single(s => s.Key == key).Value);
                }
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public IEnumerable<PostLink> GetRecentPostLinks()
        {
            IEnumerable<PostLink> recentPostLinks;

            using (var context = new ApplicationDbContext())
            {
                recentPostLinks =
                    context.Posts
                        .OrderByDescending(p => p.DateCreated)
                        .Take(5)
                        .Select(p => new PostLink { Title = p.Title, Permalink = p.Permalink })
                        .ToList();
            }

            return recentPostLinks;
        }