Skip to content

Instantly share code, notes, and snippets.

@naepalm
Last active March 21, 2016 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naepalm/655da8a198754555861f to your computer and use it in GitHub Desktop.
Save naepalm/655da8a198754555861f to your computer and use it in GitHub Desktop.
namespace Client.Web.Models
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Buzz.Hybrid;
using Buzz.Hybrid.Models;
using Client.Web.Models.ViewModels;
using Umbraco.Core.Models;
using Umbraco.Web;
class EventsLogic : BaseClass
{
#region Custom Props - Event Listing
internal static BaseModel<EventListing> AddCustomEventListingProps(BaseModel<EventListing> Model)
{
var thisNode = Umbraco.TypedContent(Model.Id);
// Model.Content.ArchivePageLink = GetArchivePageLink(thisNode);
Model.Content.MonthlyEvents = GetMonthlyEvents(Model.Content);
Model.Content.UpcomingEvents = GetUpcomingEvents(thisNode);
return Model;
}
internal static EventListing AddCustomEventListingProps(EventListing Model)
{
var thisNode = Umbraco.TypedContent(Model.Id);
// Model.ArchivePageLink = GetArchivePageLink(thisNode);
Model.MonthlyEvents = GetMonthlyEvents(Model);
Model.UpcomingEvents = GetUpcomingEvents(thisNode);
return Model;
}
private static IEnumerable<Event> GetUpcomingEvents(IPublishedContent CurrentNode)
{
return CurrentNode.Children<Event>().Where(e => e.IsUpcoming);
}
private static ILink GetArchivePageLink(IPublishedContent CurrentNode)
{
var archivePage = CurrentNode.WillWork("archivePageId")
? CurrentNode.GetSafeContent("archivePageId", Umbraco)
: null;
if (archivePage != null)
{
return new Link()
{
Url = archivePage.Url,
ContentId = archivePage.Id,
ContentTypeAlias = archivePage.DocumentTypeAlias,
Target = "_self",
Title = archivePage.Name
};
}
else
{
return null;
}
}
private static IEnumerable<EventMonth> GetMonthlyEvents(EventListing CurrentNode)
{
var events = CurrentNode.Children<Event>().Where(e => e.IsUpcoming);
var months = events.OrderBy(x => x.StartDateTime).Select(x => x.StartDateTime.ToString("MMMM")).Distinct();
return months.Select(month => new EventMonth()
{
Month = month,
Events = GetEventsByMonth(month, events)
}).ToList();
}
/// <summary>
/// Gets the events by month.
/// </summary>
/// <param name="month">
/// The month.
/// </param>
/// <param name="events">
/// A list of <see cref="IPublishedContent"/> from Umbraco.
/// </param>
/// <returns>
/// A collection of <see cref="Event"/> by month.
/// </returns>
private static IEnumerable<Event> GetEventsByMonth(string month, IEnumerable<IPublishedContent> events)
{
var returnEvents = new List<Event>();
var eventList = events.Where(x => x.GetPropertyValue<DateTime>("EventStart").ToString("MMMM") == month);
foreach (var evnt in eventList)
{
returnEvents.Add(AddCustomEventProps(evnt as Event));
}
return returnEvents;
}
#endregion
#region Custom Props - Event
internal static BaseModel<Event> AddCustomEventProps(BaseModel<Event> Model)
{
var thisNode = Umbraco.TypedContent(Model.Id);
//Model.Content.Milestones = new List<TimelineMilestone>();
//foreach (var node in thisNode.Children<TimelineMilestone>())
//{
// Model.Content.Milestones.Add(AddCustomTimelineMilestoneProps(node));
//}
return Model;
}
internal static Event AddCustomEventProps(Event Model)
{
var thisNode = Umbraco.TypedContent(Model.Id);
//Model.Milestones = new List<TimelineMilestone>();
//foreach (var node in thisNode.Children<TimelineMilestone>())
//{
// Model.Milestones.Add(AddCustomTimelineMilestoneProps(node));
//}
return Model;
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment