using System; using System.Web.Mvc; using Orchard.ContentManagement; using Orchard.ContentManagement.Aspects; using Orchard.Core.Common.Models; using Orchard.Security; namespace Orchard.Blogs.Models { public class BlogPost : ContentPart { [HiddenInput(DisplayValue = false)] public int Id { get { return ContentItem.Id; } } public string Title { get { return this.As().Title; } set { this.As().Title = value; } } public string Slug { get { return this.As().Slug; } set { this.As().Slug = value; } } public string Text { get { return this.As().Text; } set { this.As().Text = value; } } public Blog Blog { get { return this.As().Container.As(); } set { this.As().Container = value; } } public IUser Creator { get { return this.As().Owner; } set { this.As().Owner = value; } } public bool IsPublished { get { return ContentItem.VersionRecord != null && ContentItem.VersionRecord.Published; } } public bool HasDraft { get { return ( (ContentItem.VersionRecord != null) && ( (ContentItem.VersionRecord.Published == false) || (ContentItem.VersionRecord.Published && ContentItem.VersionRecord.Latest == false))); } } public bool HasPublished { get { return IsPublished || ContentItem.ContentManager.Get(Id, VersionOptions.Published) != null; } } public DateTime? CreatedUtc { get { return this.As().CreatedUtc; } } public DateTime? PublishedUtc { get { return this.As().VersionPublishedUtc; } } public DateTime? ScheduledPublishUtc { get; set; } private string _scheduledPublishUtcDate; public string ScheduledPublishUtcDate { get { return !HasPublished && !string.IsNullOrEmpty(_scheduledPublishUtcDate) || !ScheduledPublishUtc.HasValue ? _scheduledPublishUtcDate : ScheduledPublishUtc.Value.ToShortDateString(); } set { _scheduledPublishUtcDate = value; } } private string _scheduledPublishUtcTime; public string ScheduledPublishUtcTime { get { return !HasPublished && !string.IsNullOrEmpty(_scheduledPublishUtcTime) || !ScheduledPublishUtc.HasValue ? _scheduledPublishUtcTime : ScheduledPublishUtc.Value.ToShortTimeString(); } set { _scheduledPublishUtcTime = value; } } } }