Example E3971
Visible to All Users

Scheduler for ASP.NET MVC - How to display read-only appointments

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

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

MVCSchedulerReadOnly/Controllers/HomeController.cs(vb)
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 } }
MVCSchedulerReadOnly/Models/SchedulerDataObject.cs(vb)
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 }
MVCSchedulerReadOnly/Models/SchedulerStorageProvider.cs(vb)
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 }
MVCSchedulerReadOnly/Views/Home/Index.cshtml
Razor
@model MVCSchedulerReadOnly.Models.SchedulerDataObject @Html.Partial("SchedulerPartial", Model)
MVCSchedulerReadOnly/Views/Home/SchedulerPartial.cshtml
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*@

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.