Features

A quick start Visual Studio 2015 project that you can use to start your own Scheduler implementation.

  • Basic ASP.NET MVC 5 Scheduler view
  • Loads sample resources (Y axis)
  • Loads sample events (reservations)
  • Sample drag and drop event moving event handler

The Scheduler setup in the project is very basic. Please see the Scheduler documentation for all options.

This quick start project is also available for ASP.NET MVC 4:

Requirements

  • Visual Studio 2015
  • .NET Framework 4.5.2

Included

License

Licensed for testing and evaluation purposes. You can use the source code of the tutorial if you are a licensed user of DayPilot Pro for ASP.NET MVC. Buy a license.

View

Views/Home/Index.cshtml

@using DayPilot.Web.Mvc
@using DayPilot.Web.Mvc.Enums
@using DayPilot.Web.Mvc.Events.Scheduler
@section TitleContent { ASP.NET MVC 5 Scheduler }

<h1>Scheduler</h1>

<script src="~/Scripts/DayPilot/daypilot-all.min.js"></script>

@Html.DayPilotScheduler("dp", new DayPilotSchedulerConfig()
{
    BackendUrl = @Url.Action("Scheduler", "Backend"),
    StartDate = new DateTime(2017, 1, 1),
    Days = 31,
    Scale = TimeScale.Day,
    TimeHeaders = new TimeHeaderCollection()
    {
        new TimeHeader(GroupBy.Month, "MMMM yyyy"),
        new TimeHeader(GroupBy.Day),
    },
    EventMoveHandling = EventMoveHandlingType.Notify
})

Controller

Controllers/BackendController.cs

using System.Web.Mvc;
using DayPilot.Web.Mvc;
using DayPilot.Web.Mvc.Enums;
using DayPilot.Web.Mvc.Events.Scheduler;
using TutorialMvc5SchedulerQuickStart.Data;

namespace TutorialMvc5SchedulerQuickStart.Controllers
{
    public class BackendController : Controller
    {
        public ActionResult Scheduler()
        {
            return new Dps().CallBack(this);
        }

    }

    class Dps : DayPilotScheduler
    {
        protected override void OnInit(InitArgs e)
        {
            // load resources
            Resources.Add("Resource 1", "R1");
            Resources.Add("Resource 2", "R2");

            // load events
            Events = new DataManager().GetData();
            DataIdField = "Id";
            DataTextField = "Text";
            DataResourceField = "ResourceId";
            DataStartField = "Start";
            DataEndField = "End";


            // request a full update (resources and events)
            Update(CallBackUpdateType.Full);
        }

        protected override void OnEventMove(EventMoveArgs e)
        {
            new DataManager().MoveEvent(e.Id, e.NewStart, e.NewEnd, e.NewResource);
        }
    }
}

Data Access Layer

Replace this class with your own implementation:

Data/DataManager.cs

using System;
using System.Collections.Generic;

namespace TutorialMvc5SchedulerQuickStart.Data
{
    public class DataManager
    {

        public List<Event> GetData()
        {
            List<Event> result = new List<Event>();
            
            result.Add(new Event()
            {
                Id = "1",
                Start = new DateTime(2017, 1, 5),
                End = new DateTime(2017, 1, 10),
                Text = "Event 1",
                ResourceId = "R1"
            });

            return result;
        }

        public void MoveEvent(string eId, DateTime eNewStart, DateTime eNewEnd, string eNewResource)
        {
            // add implementation here
        }
    }

    public class Event
    {
        public DateTime Start { get; set; }
        public DateTime End { get; set; }
        public string Id { get; set; }
        public string Text { get; set; }
        public string ResourceId { get; set; }
    }
}

NuGet Dependencies

packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net452" />
  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net452" />
  <package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net452" developmentDependency="true" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
</packages>