Click here to Skip to main content
15,891,423 members
Articles / Web Development / ASP.NET

MVC Schedule controls

Rate me:
Please Sign up or sign in to vote.
4.83/5 (16 votes)
8 Sep 2013LGPL310 min read 63K   3.6K   85  
MVC Schedule controls
using MvcSchedule.Objects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using System.IO;
using System.Web.UI;

namespace MvcSchedule
{

    /// <summary>
    /// Extension HTML helpers for the MvcSchedule components.
    /// </summary>
    public static class ScheduleHelpers
    {

        /// <summary>
        /// Render a general schedule using a display expression for the items
        /// </summary>
        /// <typeparam name="M">Model type</typeparam>
        /// <typeparam name="TItem">Model item type</typeparam>
        /// <param name="htmlHelper">HTML helper</param>
        /// <param name="model">The data</param>
        /// <param name="dataRangeStartExpression">Expression that yields the start of the event</param>
        /// <param name="dataRangeEndExpression">Expression that yields the end of the event</param>
        /// <param name="titleExpression">Expression that yields the title of the event</param>
        /// <param name="itemDisplayExpression">Expression that yields the way to display an item on the schedule</param>
        /// <param name="options">Options</param>
        /// <param name="dataRangeDisplayExpression">Expression that yields the way to display the start or the end of the event</param>
        /// <param name="titleDisplayExpression">Expression that yields the way to display the title of the event</param>
        /// <param name="dateHeaderDisplayExpression">Expression that yields the date to display the date header of the event. Only used when Options.SeparateDateHeader==true</param>
        /// <param name="emptyDataText">Text shown when there's no data to display</param>
        /// <returns>Html string</returns>
        public static MvcHtmlString ScheduleGeneralFor<M, TItem>(this HtmlHelper<M> htmlHelper, 
            IEnumerable<TItem> model,
            Expression<Func<TItem, object>> dataRangeStartExpression,
            Expression<Func<TItem, object>> dataRangeEndExpression,
            Expression<Func<TItem, object>> titleExpression,
            Expression<Func<TItem, string>> itemDisplayExpression,
            MvcScheduleGeneralOptions options = null,
            Expression<Func<object, string>> dataRangeDisplayExpression = null,
            Expression<Func<object, string>> titleDisplayExpression = null,
            Expression<Func<DateTime, string>> dateHeaderDisplayExpression = null,
            string emptyDataText = null)
        {
            var sch = new ScheduleGeneral<TItem>();
            sch.DataRangeStartExpression = dataRangeStartExpression;
            sch.DataRangeEndExpression = dataRangeEndExpression;
            sch.TitleExpression = titleExpression;
            sch.ItemDisplayExpression = itemDisplayExpression;
            sch.DataRangeDisplayExpression = dataRangeDisplayExpression;
            sch.TitleDisplayExpression = titleDisplayExpression;
            sch.DateHeaderDisplayExpression = dateHeaderDisplayExpression;
            sch.EmptyDataText = emptyDataText;
            sch.Options = options;

            return MvcHtmlString.Create(sch.RenderTable(model, htmlHelper));
        }

        /// <summary>
        /// Render a general schedule using a partial view for the items
        /// </summary>
        /// <typeparam name="M"></typeparam>
        /// <typeparam name="TItem"></typeparam>
        /// <param name="htmlHelper"></param>
        /// <param name="model"></param>
        /// <param name="dataRangeStartExpression">Expression that yields the start of the event</param>
        /// <param name="dataRangeEndExpression">Expression that yields the end of the event</param>
        /// <param name="titleExpression">Expression that yields the title of the event</param>
        /// <param name="itemPartialViewName">Name of the partial view that displays the item on the schedule</param>
        /// <param name="options">Options</param>
        /// <param name="dataRangeDisplayExpression">Expression that yields the way to display the start or the end of the event</param>
        /// <param name="titleDisplayExpression">Expression that yields the way to display the title of the event</param>
        /// <param name="dateHeaderDisplayExpression">Expression that yields the date to display the date header of the event. Only used when Options.SeparateDateHeader==true</param>
        /// <param name="emptyDataText">Text shown when there's no data to display</param>
        /// <returns></returns>
        public static MvcHtmlString ScheduleGeneralFor<M, TItem>(this HtmlHelper<M> htmlHelper,
            IEnumerable<TItem> model,
            Expression<Func<TItem, object>> dataRangeStartExpression,
            Expression<Func<TItem, object>> dataRangeEndExpression,
            Expression<Func<TItem, object>> titleExpression,
            string itemPartialViewName,
            MvcScheduleGeneralOptions options = null,
            Expression<Func<object, string>> dataRangeDisplayExpression = null,
            Expression<Func<object, string>> titleDisplayExpression = null,
            Expression<Func<DateTime, string>> dateHeaderDisplayExpression = null,
            string emptyDataText = null)
        {
            var sch = new ScheduleGeneral<TItem>();
            sch.DataRangeStartExpression = dataRangeStartExpression;
            sch.DataRangeEndExpression = dataRangeEndExpression;
            sch.TitleExpression = titleExpression;
            sch.ItemPartialViewName = itemPartialViewName;
            sch.DataRangeDisplayExpression = dataRangeDisplayExpression;
            sch.TitleDisplayExpression = titleDisplayExpression;
            sch.DateHeaderDisplayExpression = dateHeaderDisplayExpression;
            sch.EmptyDataText = emptyDataText;
            sch.Options = options;

            return MvcHtmlString.Create(sch.RenderTable(model, htmlHelper));
        }

        /// <summary>
        /// Render a calendar schedule using a display expression for the items
        /// </summary>
        /// <typeparam name="M"></typeparam>
        /// <typeparam name="TItem"></typeparam>
        /// <param name="htmlHelper"></param>
        /// <param name="model"></param>
        /// <param name="startTimeExpression">Expression that yields the start time of the event</param>
        /// <param name="endTimeExpression">Expression that yields the end time of the event</param>
        /// <param name="dateExpression">Expression that yields the date of the event. 
        /// Ignored when TimeExpressionsContainDate==true. 
        /// When TimeExpressionsContainDate==false, this should yield a result of type Date</param>
        /// <param name="itemDisplayExpression">Expression that yields the way to display the item on the schedule</param>
        /// <param name="options">Options</param>
        /// <param name="timeDisplayExpression">Expression that yields the way to display the time of the event</param>
        /// <param name="dateDisplayExpression">Expression that yields the way to display the date of the event</param>
        /// <param name="emptyDataText">Text shown when there's no data to display</param>
        /// <returns></returns>
        public static MvcHtmlString ScheduleCalendarFor<M, TItem>(this HtmlHelper<M> htmlHelper,
            IEnumerable<TItem> model,
            Expression<Func<TItem, object>> startTimeExpression,
            Expression<Func<TItem, object>> endTimeExpression,
            Expression<Func<TItem, object>> dateExpression,
            Expression<Func<TItem, string>> itemDisplayExpression,
            MvcScheduleCalendarOptions options = null,
            Expression<Func<object, string>> timeDisplayExpression = null,
            Expression<Func<object, string>> dateDisplayExpression = null,
            string emptyDataText = null)
        {
            var sch = new ScheduleCalendar<TItem>();
            sch.StartTimeExpression = startTimeExpression;
            sch.EndTimeExpression = endTimeExpression;
            sch.DateExpression = dateExpression;
            sch.ItemDisplayExpression = itemDisplayExpression;
            sch.TimeDisplayExpression = timeDisplayExpression;
            sch.DateDisplayExpression = dateDisplayExpression;
            sch.EmptyDataText = emptyDataText;
            sch.Options = options;
            
            return MvcHtmlString.Create(sch.RenderTable(model, htmlHelper));
        }

        /// <summary>
        /// Render a calendar schedule using a partial view for the items
        /// </summary>
        /// <typeparam name="M"></typeparam>
        /// <typeparam name="TItem"></typeparam>
        /// <param name="htmlHelper"></param>
        /// <param name="model"></param>
        /// <param name="startTimeExpression">Expression that yields the start time of the event</param>
        /// <param name="endTimeExpression">Expression that yields the end time of the event</param>
        /// <param name="dateExpression">Expression that yields the date of the event. 
        /// Ignored when TimeExpressionsContainDate==true. 
        /// When TimeExpressionsContainDate==false, this should yield a result of type Date</param>
        /// <param name="itemPartialViewName">Name of the partial view that displays the item on the schedule</param>
        /// <param name="options">Options</param>
        /// <param name="timeDisplayExpression">Expression that yields the way to display the time of the event</param>
        /// <param name="dateDisplayExpression">Expression that yields the way to display the date of the event</param>
        /// <param name="emptyDataText">Text shown when there's no data to display</param>
        /// <returns></returns>
        public static MvcHtmlString ScheduleCalendarFor<M, TItem>(this HtmlHelper<M> htmlHelper,
            IEnumerable<TItem> model,
            Expression<Func<TItem, object>> startTimeExpression,
            Expression<Func<TItem, object>> endTimeExpression,
            Expression<Func<TItem, object>> dateExpression,
            string itemPartialViewName,
            MvcScheduleCalendarOptions options = null,
            Expression<Func<object, string>> timeDisplayExpression = null,
            Expression<Func<object, string>> dateDisplayExpression = null,
            string emptyDataText = null)
        {
            var sch = new ScheduleCalendar<TItem>();
            sch.StartTimeExpression = startTimeExpression;
            sch.EndTimeExpression = endTimeExpression;
            sch.DateExpression = dateExpression;
            sch.ItemPartialViewName = itemPartialViewName;
            sch.TimeDisplayExpression = timeDisplayExpression;
            sch.DateDisplayExpression = dateDisplayExpression;
            sch.EmptyDataText = emptyDataText;
            sch.Options = options;

            return MvcHtmlString.Create(sch.RenderTable(model, htmlHelper));
        }

    }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Web Developer
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions