This example demonstrates how to add the Scheduler extension to an application. The Scheduler is bound to a data source and displays read-only appointments. Refer to the following article for more information: Lesson 1 - Use Scheduler to Display Appointments in Read-Only Mode.
Call the Scheduler's Bind(filterAppointmentMethod, filterResourceMethod) method overload to hide specific appointments and resources. After that, call the Bind(appointmentDataObject, resourceDataObject) method overload to bind the extension to data.
Files to Review
- HomeController.cs (VB: HomeController.vb)
- SchedulerDataObject.cs (VB: SchedulerDataObject.vb)
- SchedulerStorageProvider.cs (VB: SchedulerStorageProvider.vb)
- Index.cshtml
- SchedulerPartial.cshtml
Documentation
- Lesson 1 - Display Read-Only Appointments in Scheduler
- Lesson 2 - Edit Data in Scheduler
- Lesson 3 - Use Scheduler in Complex Views
More Examples
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
C#using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DevExpress.Web.Mvc;
using MVCSchedulerReadOnly.Models;
namespace MVCSchedulerReadOnly.Views
{
public class HomeController : Controller
{
//
// GET: /Home/
#region #commonactions
public ActionResult Index()
{
return View(SchedulerDataHelper.DataObject);
}
public ActionResult SchedulerPartial()
{
return PartialView("SchedulerPartial", SchedulerDataHelper.DataObject);
}
#endregion #commonactions
}
}
C#using System.Linq;
namespace MVCSchedulerReadOnly.Models
{
#region #SchedulerDataObject
public class SchedulerDataObject
{
public System.Collections.IEnumerable Appointments { get; set; }
public System.Collections.IEnumerable Resources { get; set; }
}
#endregion #SchedulerDataObject
#region #SchedulerDataHelper
public class SchedulerDataHelper
{
public static System.Collections.IEnumerable GetResources()
{
SchedulingDataClassesDataContext db = new SchedulingDataClassesDataContext();
return from res in db.DBResources select res;
}
public static System.Collections.IEnumerable GetAppointments()
{
SchedulingDataClassesDataContext db = new SchedulingDataClassesDataContext();
return from apt in db.DBAppointments select apt;
}
public static SchedulerDataObject DataObject
{
get
{
return new SchedulerDataObject()
{
Appointments = GetAppointments(),
Resources = GetResources()
};
}
}
}
#endregion #SchedulerDataHelper
}
C#using DevExpress.Web.Mvc;
namespace MVCSchedulerReadOnly.Models
{
#region #SchedulerStorageProvider
public class SchedulerStorageProvider
{
static MVCxAppointmentStorage defaultAppointmentStorage;
public static MVCxAppointmentStorage DefaultAppointmentStorage
{
get
{
if (defaultAppointmentStorage == null)
defaultAppointmentStorage = CreateDefaultAppointmentStorage();
return defaultAppointmentStorage;
}
}
static MVCxAppointmentStorage CreateDefaultAppointmentStorage()
{
MVCxAppointmentStorage appointmentStorage = new MVCxAppointmentStorage();
appointmentStorage.Mappings.AppointmentId = "UniqueID";
appointmentStorage.Mappings.Start = "StartDate";
appointmentStorage.Mappings.End = "EndDate";
appointmentStorage.Mappings.Subject = "Subject";
appointmentStorage.Mappings.Description = "Description";
appointmentStorage.Mappings.Location = "Location";
appointmentStorage.Mappings.AllDay = "AllDay";
appointmentStorage.Mappings.Type = "Type";
appointmentStorage.Mappings.RecurrenceInfo = "RecurrenceInfo";
appointmentStorage.Mappings.ReminderInfo = "ReminderInfo";
appointmentStorage.Mappings.Label = "Label";
appointmentStorage.Mappings.Status = "Status";
appointmentStorage.Mappings.ResourceId = "ResourceID";
return appointmentStorage;
}
static MVCxResourceStorage defaultResourceStorage;
public static MVCxResourceStorage DefaultResourceStorage
{
get
{
if (defaultResourceStorage == null)
defaultResourceStorage = CreateDefaultResourceStorage();
return defaultResourceStorage;
}
}
static MVCxResourceStorage CreateDefaultResourceStorage()
{
MVCxResourceStorage resourceStorage = new MVCxResourceStorage();
resourceStorage.Mappings.ResourceId = "ResourceID";
resourceStorage.Mappings.Caption = "ResourceName";
return resourceStorage;
}
}
#endregion #SchedulerStorageProvider
}
Razor@model MVCSchedulerReadOnly.Models.SchedulerDataObject
@Html.Partial("SchedulerPartial", Model)
Razor@*#region #SchedulerPartial*@
@Html.DevExpress().Scheduler(
settings => {
settings.Name = "scheduler";
settings.CallbackRouteValues = new { Controller = "Home", Action = "SchedulerPartial" };
settings.Storage.Appointments.Assign(MVCSchedulerReadOnly.Models.SchedulerStorageProvider.DefaultAppointmentStorage);
settings.Storage.Resources.Assign(MVCSchedulerReadOnly.Models.SchedulerStorageProvider.DefaultResourceStorage);
settings.Storage.EnableReminders = false;
settings.OptionsCustomization.AllowAppointmentCreate = DevExpress.XtraScheduler.UsedAppointmentType.None;
settings.OptionsCustomization.AllowAppointmentEdit = DevExpress.XtraScheduler.UsedAppointmentType.None;
settings.OptionsCustomization.AllowAppointmentDelete = DevExpress.XtraScheduler.UsedAppointmentType.None;
settings.Width = 800;
settings.Views.DayView.Styles.ScrollAreaHeight = 600;
settings.Views.DayView.DayCount = 2;
settings.Start = new DateTime(2015, 4, 15);
settings.GroupType = SchedulerGroupType.Resource;
}).Bind(
//Hide appointments containing "Test" in their subject lines.
(e) => {
if (((Appointment)e.Object).Subject.Contains("Test")) e.Cancel = true;
},
//Hide appointments assigned to resources containing "OPEL" in their captions.
(e) => {
if (((Resource)e.Object).Caption.Contains("OPEL")) e.Cancel = true;
}
).Bind(Model.Appointments, Model.Resources).GetHtml()
@*#endregion #SchedulerPartial*@