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
- SchedulerPartial.cshtml
- HomeController.cs (VB: HomeController.vb)
- AppointmentDataAccessor.cs (VB: AppointmentDataAccessor.vb)
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
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*@
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
}
}
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
}