public ActionResult Details(int id) { if (!this.Data.Snippets.All().Any(s => s.Id == id)) { return HttpNotFound(); } var snippet = this.Data.Snippets.All() .FirstOrDefault(s => s.Id == id); var output = new ModelWrapper { Snippet = snippet }; return View("Details",output); }
public PartialViewResult LastestSnippets() { var lastestSnippets = Data.Snippets.All() .OrderByDescending(s => s.CreatedOn) .Take(5) .Select(s => new MinSnippetsViewModel { Title = s.Title, Labels = s.Labels }); var output = new ModelWrapper{LastestSnippetsViewModel = lastestSnippets.ToList()}; return PartialView("_SnippetsPartial", output); }
// GET: Snippets public ActionResult Index() { var snippets = this.Data.Snippets.All() .OrderByDescending(s => s.CreatedOn) .Select(s => new MinSnippetsViewModel { Title = s.Title, Labels = s.Labels }); var output = new ModelWrapper { LastestSnippetsViewModel = snippets.ToList() }; return View("AllSnippets", output); }
public PartialViewResult BestLabels() { var bestLabels = this.Data.Labels.All() .OrderByDescending(l => l.Snippets.Count) .Take(5) .Select(l => new BestLabelsViewModel { Name = l.Text, Count = l.Snippets.Count }); var output = new ModelWrapper { BestLabelsViewModel = bestLabels.ToList() }; return PartialView("_BestLabelsPartial", output); }
public PartialViewResult LastestComments() { var lastestComments = this.Data.Comments.All() .OrderByDescending(c => c.CreatedOn) .Take(5) .Select(c => new LastestCommentsViewModel { Author = c.Author.UserName, Content = c.Content, CreatedOn = c.CreatedOn, Snippet = c.Snippet.Title }); var output = new ModelWrapper { LastestCommentsViewModel = lastestComments.ToList() }; return PartialView("_LastestCommentsPartial", output); }
public ActionResult Post(ModelWrapper m) { var userId = User.Identity.GetUserId(); var comment = new Comment { Content = m.CommentBindingModel.Content, Author = this.Data.Users.All().FirstOrDefault(u => u.Id == userId), CreatedOn = DateTime.Now, Snippet = this.Data.Snippets.All().FirstOrDefault(s => s.Id == m.CommentBindingModel.SnippetId) }; this.Data.Comments.Add(comment); this.Data.SaveChanges(); return RedirectToAction("Details","Snippets", new {id = m.CommentBindingModel.SnippetId}); }
public ActionResult Index() { var modelWrapper = new ModelWrapper(); var lastestSnippets = Data.Snippets.All() .OrderByDescending(s => s.CreatedOn) .Take(5) .Select(s => new MinSnippetsViewModel { Title = s.Title, Labels = s.Labels }); var lastestComments = this.Data.Comments.All() .OrderByDescending(c => c.CreatedOn) .Take(5) .Select(c => new LastestCommentsViewModel { Author = c.Author.UserName, Content = c.Content, CreatedOn = c.CreatedOn, Snippet = c.Snippet.Title }); var bestLabels = this.Data.Labels.All() .OrderByDescending(l => l.Snippets.Count) .Take(5) .Select(l => new BestLabelsViewModel { Name = l.Text, Count = l.Snippets.Count }); return View(); }