Click here to Skip to main content
15,885,790 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 MvcSchedule.Objects;
using MvcScheduleTestAppCS.Models;
using MvcScheduleTestAppCS.ViewModels;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcScheduleTestAppCS.Controllers
{
    public class HomeController : Controller
    {

        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to the MvcSchedule demo's";
            ViewBag.CssFile = Url.Content("~/Content/demo1.css");
            return View();
        }

        #region Demo1

        public ActionResult Demo1()
        {
            ViewBag.Message = "Demo 1";
            ViewBag.CssFile = Url.Content("~/Content/demo1.css");
            ViewBag.DaysOfWeek = MvcScheduleTestAppCS.Utility.DaysOfWeekList;

            var vm = new Demo1ViewModel();
            ScheduleTestDataEntities ctx = new ScheduleTestDataEntities();
            vm.Data = ctx.demo1.ToList();
            vm.Options = new MvcScheduleCalendarOptions
            {
                Layout = LayoutEnum.Vertical,
                NumberOfRepetitions = 2,
                TimeScaleInterval = 30,
                StartOfTimeScale = new TimeSpan(8, 0, 0),
                EndOfTimeScale = new TimeSpan(12, 0, 0),
                IncludeEndValue = false,
                ShowValueMarks = true,
                StartDate = new DateTime(2013, 3, 11),
                ItemCss = "item",
                TimeCss = "rangeheader",
                DateCss = "title",
                BackgroundCss = "bground"
            };
            return View(vm);
        }

        [HttpPost]
        public ActionResult Demo1(Demo1ViewModel vm)
        {
            ViewBag.Message = "Demo 1";
            ViewBag.CssFile = Url.Content("~/Content/demo1.css");
            ViewBag.DaysOfWeek = MvcScheduleTestAppCS.Utility.DaysOfWeekList;

            // data is not bound two-ways, so load it again
            ScheduleTestDataEntities ctx = new ScheduleTestDataEntities();
            vm.Data = ctx.demo1.ToList();
            return View(vm);
        }

        #endregion

        #region Demo2

        public ActionResult Demo2()
        {
            ViewBag.Message = "Demo 2";
            ViewBag.CssFile = Url.Content("~/Content/demo2.css");

            var vm = new Demo2ViewModel();
            ScheduleTestDataEntities ctx = new ScheduleTestDataEntities();
            vm.Data = ctx.demo2.ToList();
            vm.Options = new MvcScheduleGeneralOptions
            {
                Layout = LayoutEnum.Horizontal,
                SeparateDateHeader = true,
                FullTimeScale = false,
                TimeScaleInterval = 60,
                StartOfTimeScale = new TimeSpan(8, 0, 0),
                EndOfTimeScale = new TimeSpan(18, 0, 0),
                IncludeEndValue = false,
                ShowValueMarks = false,
                ItemCss = "normal",
                AlternatingItemCss = "normal2",
                RangeHeaderCss = "heading",
                TitleCss = "heading",
                BackgroundCss = "bground"
            };
            return View(vm);
        }

        [HttpPost]
        public ActionResult Demo2(Demo2ViewModel vm)
        {
            ViewBag.Message = "Demo 2";
            ViewBag.CssFile = Url.Content("~/Content/demo2.css");

            // data is not bound two-ways, so load it again
            ScheduleTestDataEntities ctx = new ScheduleTestDataEntities();
            vm.Data = ctx.demo2.ToList();
            return View(vm);
        }

        #endregion

        #region Demo2

        public ActionResult Demo3()
        {
            ViewBag.Message = "Demo 3";
            ViewBag.CssFile = Url.Content("~/Content/demo2.css");

            var vm = new Demo3ViewModel();
            ScheduleTestDataEntities ctx = new ScheduleTestDataEntities();
            vm.Data = ctx.demo3.ToList();
            vm.Options = new MvcScheduleGeneralOptions
            {
                Layout = LayoutEnum.Horizontal,
                SeparateDateHeader = true,
                FullTimeScale = false,
                TimeScaleInterval = 60,
                StartOfTimeScale = new TimeSpan(8, 0, 0),
                EndOfTimeScale = new TimeSpan(18, 0, 0),
                IncludeEndValue = false,
                ShowValueMarks = false,
                ItemCss = "normal",
                AlternatingItemCss = "normal2",
                RangeHeaderCss = "heading",
                TitleCss = "heading",
                BackgroundCss = "empty"
            };
            return View(vm);
        }

        [HttpPost]
        public ActionResult Demo3(Demo3ViewModel vm)
        {
            ViewBag.Message = "Demo 3";
            ViewBag.CssFile = Url.Content("~/Content/demo2.css");

            // data is not bound two-ways, so load it again
            ScheduleTestDataEntities ctx = new ScheduleTestDataEntities();
            vm.Data = ctx.demo3.ToList();
            return View(vm);
        }

        #endregion

        public ActionResult Demo4()
        {
            ViewBag.Message = "Demo 4 Calendar with partial view";
            ViewBag.CssFile = Url.Content("~/Content/demo1.css");
            ViewBag.DaysOfWeek = MvcScheduleTestAppCS.Utility.DaysOfWeekList;

            var vm = new Demo4ViewModel();
            ScheduleTestDataEntities ctx = new ScheduleTestDataEntities();
            vm.Data = ctx.demo4.ToList();
            vm.Options = new MvcScheduleCalendarOptions
            {
                Layout = LayoutEnum.Vertical,
                NumberOfRepetitions = 2,
                TimeExpressionsContainDate = true,
                TimeScaleInterval = 30,
                StartOfTimeScale = new TimeSpan(8, 0, 0),
                EndOfTimeScale = new TimeSpan(12, 0, 0),
                IncludeEndValue = false,
                ShowValueMarks = true,
                StartDate = new DateTime(2013, 3, 11),
                ItemCss = "item",
                TimeCss = "rangeheader",
                DateCss = "title",
                BackgroundCss = "bground"
            };
            return View(vm);
        }

        [HttpPost]
        public ActionResult Demo4(Demo4ViewModel vm)
        {
            ViewBag.Message = "Demo 4 Calendar with partial view";
            ViewBag.CssFile = Url.Content("~/Content/demo1.css");
            ViewBag.DaysOfWeek = MvcScheduleTestAppCS.Utility.DaysOfWeekList;

            // data is not bound two-ways, so load it again
            ScheduleTestDataEntities ctx = new ScheduleTestDataEntities();
            vm.Data = ctx.demo4.ToList();
            return View(vm);
        }
        
        public ActionResult About()
        {
            return View();
        }
    }
}

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