public ActionResult Index() { var mostRecentBlogPost = _blogPostDao.GetMostRecent(); var imageForPost = _blogPostDao.GetImagesForPost(mostRecentBlogPost); var firstOrDefault = imageForPost.FirstOrDefault(); if (firstOrDefault != null) { var model = new HomePageViewModel { MostRecentBlogPost = mostRecentBlogPost, ImageForPost = firstOrDefault.Image //too simple should eventually be a specific image }; return View(model); } else { var model = new HomePageViewModel { MostRecentBlogPost = mostRecentBlogPost, ImageForPost = _blogPostDao.GetDefaultImage() }; return View(model); } }
public ActionResult Index() { var datacontext = new SiteDataDataContext(); HomePageViewModel model = new HomePageViewModel(); model.MostRecentBlogPost = datacontext.BlogPosts.OrderByDescending(post => post.Date).First(); return View(model); }