﻿using System;

namespace Blog.Data
{
    public class Post
    {
        public int Id { get; set; }

        public string Url { get; set; }

        public string Title { get; set; }

        public string Description { get; set; }

        public string ComputedDescription
        {
            get
            {
                if (!string.IsNullOrEmpty(this.Description))
                {
                    return this.Description;
                }

                var description = this.Content.Split(new string[] { "<!-- more -->", "<!--more-->" }, StringSplitOptions.RemoveEmptyEntries);

                if (description.Length > 0)
                {
                    return description[0];
                }

                return string.Empty;
            }
        }

        public string Content { get; set; }

        public DateTime? PublicationDate { get; set; }

        public int CategoryId { get; set; }

        public virtual Category Category { get; set; }
    }
}

﻿using System;
using System.Linq.Expressions;

namespace Blog.Data
{
    public class Post
    {
        public int Id { get; set; }

        public string Url { get; set; }

        public string Title { get; set; }

        public string Description { get; set; }

        public string ComputedDescription
        {
            get
            {
                if (!string.IsNullOrEmpty(this.Description))
                {
                    return this.Description;
                }

                var description = this.Content.Split(new string[] { "<!-- more -->", "<!--more-->" }, StringSplitOptions.RemoveEmptyEntries);

                if (description.Length > 0)
                {
                    return description[0];
                }

                return string.Empty;
            }
        }

        public string Content { get; set; }

        public DateTime? PublicationDate { get; set; }

        public int CategoryId { get; set; }

        public virtual Category Category { get; set; }


        public static Expression<Func<Post, bool>> IsPublished = post => post.PublicationDate.HasValue && DateTime.Now > post.PublicationDate;
    }
}

Add expression indicating if a post is published
Add expression indicating if a post is published
