Click here to Skip to main content
15,884,388 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 62.9K   3.6K   85  
MVC Schedule controls
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace MvcSchedule.Data
{

	/// <summary>
	/// Wrapper list for the data.
	/// With this list, we can add extra items if necessary without touching the data itself.
	/// </summary>
    internal class ScheduleItemDataList<TItem> : List<ScheduleItemData<TItem>>
	{
        private Expression<Func<TItem, object>> _dataRangeStartExpression;
        private Expression<Func<TItem, object>> _dataRangeEndExpression;
        private Expression<Func<TItem, object>> _titleExpression;

        public ScheduleItemDataList(Expression<Func<TItem, object>> dataRangeStartExpression,
                                    Expression<Func<TItem, object>> dataRangeEndExpression,
                                    Expression<Func<TItem, object>> titleExpression)
		{
            _dataRangeStartExpression = dataRangeStartExpression;
            _dataRangeEndExpression = dataRangeEndExpression;
            _titleExpression = titleExpression;
		}

		public void AddItem(TItem dataItem)
		{
            object startValue = _dataRangeStartExpression.Compile().Invoke(dataItem);
            object endValue = _dataRangeEndExpression.Compile().Invoke(dataItem);
            object titleValue = null;
            if(_titleExpression != null)
                titleValue = _titleExpression.Compile().Invoke(dataItem);
            ScheduleItemData<TItem> sid = new ScheduleItemData<TItem>(dataItem, startValue, endValue, titleValue);
			base.Add(sid);
		}

	}

}

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