Add BlogPostViewModel for view specific processing
This commit is contained in:
parent
647696aa92
commit
dda522d221
6 changed files with 34 additions and 18 deletions
|
@ -26,7 +26,8 @@ namespace Website.Controllers
|
||||||
public async Task<IActionResult> View(int id)
|
public async Task<IActionResult> View(int id)
|
||||||
{
|
{
|
||||||
var post = await _repo.GetPostAsync(id);
|
var post = await _repo.GetPostAsync(id);
|
||||||
return View(post);
|
var model = new BlogPostViewModel(post);
|
||||||
|
return View(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,8 @@ namespace Website.Controllers
|
||||||
public async Task<IActionResult> Index()
|
public async Task<IActionResult> Index()
|
||||||
{
|
{
|
||||||
var post = await _blogRepo.GetLatestPostAsync();
|
var post = await _blogRepo.GetLatestPostAsync();
|
||||||
return View(post);
|
var model = new BlogPostViewModel(post);
|
||||||
|
return View(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,17 +16,12 @@ namespace Website.Models
|
||||||
UserId = state.User_Id;
|
UserId = state.User_Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlogPost()
|
public int Id { get; private set; }
|
||||||
{
|
public string Title { get; private set; }
|
||||||
|
public string Content { get; private set; }
|
||||||
}
|
public DateTime Timestamp { get; private set; }
|
||||||
|
public string Draft { get; private set; }
|
||||||
public int Id { get; set; }
|
public string Url { get; private set; }
|
||||||
public string Title { get; set; }
|
public int UserId { get; private set; }
|
||||||
public string Content { get; set; }
|
|
||||||
public DateTime Timestamp { get; set; }
|
|
||||||
public string Draft { get; set; }
|
|
||||||
public string Url { get; set; }
|
|
||||||
public int UserId { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
21
Website/ViewModels/BlogPostViewModel.cs
Normal file
21
Website/ViewModels/BlogPostViewModel.cs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
using System;
|
||||||
|
using Website.Models;
|
||||||
|
|
||||||
|
namespace Website.ViewModels
|
||||||
|
{
|
||||||
|
public class BlogPostViewModel
|
||||||
|
{
|
||||||
|
public BlogPostViewModel(BlogPost blogPost)
|
||||||
|
{
|
||||||
|
Title = blogPost.Title;
|
||||||
|
Content = blogPost.Content;
|
||||||
|
Timestamp = blogPost.Timestamp;
|
||||||
|
Url = blogPost.Url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Title { get; private set; }
|
||||||
|
public string Content { get; private set; }
|
||||||
|
public DateTime Timestamp { get; private set; }
|
||||||
|
public string Url { get; private set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
@using Website.Models;
|
@model BlogPostViewModel;
|
||||||
@model BlogPost;
|
|
||||||
|
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Blog";
|
ViewData["Title"] = "Blog";
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
@using Website.Models;
|
@model BlogPostViewModel;
|
||||||
@model BlogPost;
|
|
||||||
|
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Home";
|
ViewData["Title"] = "Home";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue