Example E3984
Visible to All Users

Scheduler for ASP.NET MVC - How to implement the insert/update/delete appointment functionality

This example demonstrates how to implement CRUD operations in the Scheduler extension.

Refer to the following article for more information: Lesson 2 - Implement the Insert/Update/Delete Appointment Functionality

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

MVCSchedulerEditable/Views/Home/SchedulerPartial.cshtml
Razor
@*#region #SchedulerPartial*@ @Html.DevExpress().Scheduler( settings => { settings.Name = "scheduler"; settings.CallbackRouteValues = new { Controller = "Home", Action = "SchedulerPartial" }; settings.EditAppointmentRouteValues = new { Controller = "Home", Action = "EditAppointment" }; settings.Storage.Appointments.Assign(MVCSchedulerEditable.Models.SchedulerStorageProvider.DefaultAppointmentStorage); settings.Storage.Resources.Assign(MVCSchedulerEditable.Models.SchedulerStorageProvider.DefaultResourceStorage); settings.Storage.EnableReminders = true; settings.ActiveViewType = SchedulerViewType.FullWeek; settings.Views.FullWeekView.Styles.ScrollAreaHeight = 600; settings.Start = new DateTime(2015, 4, 18); }).Bind(Model.Appointments, Model.Resources).GetHtml() @*#endregion #SchedulerPartial*@
MVCSchedulerEditable/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 MVCSchedulerEditable.Models; namespace MVCSchedulerEditable.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 #region #editactions public ActionResult EditAppointment() { UpdateAppointment(); return PartialView("SchedulerPartial", SchedulerDataHelper.DataObject); } static void UpdateAppointment() { DBAppointment[] insertedAppointments = SchedulerExtension.GetAppointmentsToInsert<DBAppointment>("scheduler", SchedulerDataHelper.GetAppointments(), SchedulerDataHelper.GetResources(), SchedulerStorageProvider.DefaultAppointmentStorage, SchedulerStorageProvider.DefaultResourceStorage); foreach (var appt in insertedAppointments) { AppointmentDataAccessor.InsertAppointment(appt); } DBAppointment[] updatedAppointments = SchedulerExtension.GetAppointmentsToUpdate<DBAppointment>("scheduler", SchedulerDataHelper.GetAppointments(), SchedulerDataHelper.GetResources(), SchedulerStorageProvider.DefaultAppointmentStorage, SchedulerStorageProvider.DefaultResourceStorage); foreach (var appt in updatedAppointments) { AppointmentDataAccessor.UpdateAppointment(appt); } DBAppointment[] removedAppointments = SchedulerExtension.GetAppointmentsToRemove<DBAppointment>("scheduler", SchedulerDataHelper.GetAppointments(), SchedulerDataHelper.GetResources(), SchedulerStorageProvider.DefaultAppointmentStorage, SchedulerStorageProvider.DefaultResourceStorage); foreach (var appt in removedAppointments) { AppointmentDataAccessor.RemoveAppointment(appt); } } #endregion #editactions } }
MVCSchedulerEditable/Models/AppointmentDataAccessor.cs(vb)
C#
using System.Linq; namespace MVCSchedulerEditable.Models { #region #AppointmentDataAccessor public class AppointmentDataAccessor { public static void InsertAppointment(DBAppointment appt) { if (appt == null) return; SchedulingDataClassesDataContext db = new SchedulingDataClassesDataContext(); appt.UniqueID = appt.GetHashCode(); db.DBAppointments.InsertOnSubmit(appt); db.SubmitChanges(); } public static void UpdateAppointment(DBAppointment appt) { if (appt == null) return; SchedulingDataClassesDataContext db = new SchedulingDataClassesDataContext(); DBAppointment query = (DBAppointment)(from carSchedule in db.DBAppointments where carSchedule.UniqueID == appt.UniqueID select carSchedule).SingleOrDefault(); query.UniqueID = appt.UniqueID; query.StartDate = appt.StartDate; query.EndDate = appt.EndDate; query.AllDay = appt.AllDay; query.Subject = appt.Subject; query.Description = appt.Description; query.Location = appt.Location; query.RecurrenceInfo = appt.RecurrenceInfo; query.ReminderInfo = appt.ReminderInfo; query.Status = appt.Status; query.Type = appt.Type; query.Label = appt.Label; query.ResourceID = appt.ResourceID; db.SubmitChanges(); } public static void RemoveAppointment(DBAppointment appt) { SchedulingDataClassesDataContext db = new SchedulingDataClassesDataContext(); DBAppointment query = (DBAppointment)(from carSchedule in db.DBAppointments where carSchedule.UniqueID == appt.UniqueID select carSchedule).SingleOrDefault(); db.DBAppointments.DeleteOnSubmit(query); db.SubmitChanges(); } } #endregion #AppointmentDataAccessor }

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.