website/Website/Models/BlogPost.cs

43 lines
No EOL
947 B
C#

using System;
using Website.Data.States;
namespace Website.Models
{
public class BlogPost
{
public BlogPost() {
}
public BlogPost(BlogPostState state)
{
Id = state.Post_Id;
Title = state.Post_Title;
Content = state.Post_Content;
Timestamp = state.Post_Timestamp;
Draft = state.Post_Draft;
Url = state.Post_Url;
UserId = state.User_Id;
}
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 string Url { get; private set; }
public int UserId { get; private set; }
private void GenerateUrl() {
Url = Title.Replace(' ', '-');
}
public void UpdateTitle(string title) {
Title = title;
GenerateUrl();
}
public void UpdateDraft(string content) => Draft = content;
public void Publish() => Content = Draft;
}
}