Hi ezequie,
Thanks
for using syncfusion products.
We would
like to inform you that, we can explain how schedule control writing data in
the database.
Follow the below steps to perform the CRUD operation
with Database in schedule control.
Step 1: In view page “onCreate” event will
trigger to add/change the appointment into schedule control.When we add the
appointment this event will be triggered, appointment will be added to the
database and displayed in the schedule control.Similarly while updating
“appointments” this event will trigger and perform the edit operation and
changes reflect in the appointments.
<Code>
@(Html.EJ().Schedule("Schedule1")
.Width("100%")
.Height("525px")
.TimeZone("UTC +5:30")
.CurrentDate(new DateTime(2014,5,2))
@* Data
source property assigns the local json data or remote(url binding) data to the
Schedule control@*
.AppointmentSettings(fields =>
fields.Datasource((IEnumerable)ViewBag.datasource)
@* Mapper
fields id,subject,description,startTime,endTime,allDay,recurrence,recurrenceRule
from database@*
.Id("Id")
.Subject("Subject")
.StartTime("StartTime")
.EndTime("EndTime")
.AllDay("AllDay")
.Recurrence("Recurrence")
.RecurrenceRule("RecurrenceRule"))
.ScheduleClientSideEvents(evt=>
evt.Create("onCreate"))
)
@* “onCreate”
event triggered @*
function onCreate(args) {
this._dataManager.dataSource.crudUrl
= "/Schedule/Batch";
@* Here
we need to pass the post action name for the crud operation and this will
trigger when the add/edit/delete appointments@*
}
</Code>
Step 2: Define the controller page with the following code
snippet to read the appointments details from the data base.
<Code>
public ActionResult Index()
{
//Data pass
from controller page to view page
var DataSource = new ScheduleDataDataContext().DefaultSchedules.ToList();
ViewBag.dataSource = DataSource;
return View();
}
</Code>
Step 3: Create the model (Ex. EditParams.cs) and define the class as shown below.
We need to create this class for perform the CRUD operation. When we add the
appointment in schedule, values will come to the “added” variable in controller
page; similarly while update values will come to the “changed” variable in
controller page.
And the “key” property will help to
receive the appointment “id” value while deleting, and “action” holds the
details of the current action. And the “value” is used to store and process appointment
details in controller page.
<Code>
public class EditParams
{
public string key { get; set; }
public string action { get; set; }
public List<DefaultSchedule> added
{ get; set; }
public List<DefaultSchedule>
changed { get; set; }
public DefaultSchedule value { get; set; }
}
</Code>
Step 4: And define
the “JsonResult” action method (Ex. CRUD) in the controller page to perform the
“add/edit/delete” operations to the data base. For this, add the following code
snippet in the controller page.
<Code>
public JsonResult Batch(EditParams param)
{
if (param.action == "insert" || (param.action == "batch" && param.added
!= null)) // this
block of code will execute while inserting the appointments
{
var value = param.action == "insert" ? param.value :
param.added[0];
int intMax = db.DefaultSchedules.ToList().Count > 0 ?
db.DefaultSchedules.ToList().Max(p => p.Id) : 1;
DateTime startTime = Convert.ToDateTime(value.StartTime);
DateTime endTime = Convert.ToDateTime(value.EndTime);
var currentTimeZone = TimeZone.CurrentTimeZone;
DefaultSchedule appoint = new DefaultSchedule()
{
Id = intMax + 1,
StartTime =
startTime.ToUniversalTime(),
EndTime = endTime.ToUniversalTime(),
Subject = value.Subject,
Location = value.Location,
Description = value.Description,
Owner = value.Owner,
Priority
= value.Priority,
Recurrence = value.Recurrence,
RecurrenceType = value.RecurrenceType,
Reminder = value.Reminder,
Categorize = value.Categorize,
AllDay = value.AllDay,
RecurrenceEndDate =
value.RecurrenceEndDate != null ? Convert.ToDateTime(value.RecurrenceEndDate).ToUniversalTime() :
endTime.ToUniversalTime(),
RecurrenceStartDate =
value.RecurrenceStartDate != null ? Convert.ToDateTime(value.RecurrenceStartDate).ToUniversalTime() :
startTime.ToUniversalTime(),
RecurrenceRule = value.RecurrenceRule,
PatientName=value.PatientName,
AppointmentType=value.AppointmentType
};
db.DefaultSchedules.InsertOnSubmit(appoint);
db.SubmitChanges();
}
else if (param.action == "remove") // this
block of code will execute while removing the appointment
{
DefaultSchedule app = db.DefaultSchedules.Where(c => c.Id == Convert.ToInt32(param.key)).FirstOrDefault();
if (app != null)
db.DefaultSchedules.DeleteOnSubmit(app);
db.SubmitChanges();
}
else if ((param.action == "batch" && param.changed != null) || param.action == "update") // this block of code will execute while updating the
appointment
{
var value = param.action == "update" ? param.value : param.changed[0];
var filterData = db.DefaultSchedules.Where(c => c.Id == Convert.ToInt32(value.Id));
if (filterData.Count() > 0)
{
DateTime startTime = Convert.ToDateTime(value.StartTime);
DateTime endTime = Convert.ToDateTime(value.EndTime);
DefaultSchedule appoint = db.DefaultSchedules.Single(A => A.Id == Convert.ToInt32(value.Id));
appoint.StartTime =
startTime.ToUniversalTime();
appoint.EndTime =
endTime.ToUniversalTime();
appoint.Subject = value.Subject;
appoint.Location = value.Location;
appoint.Description
= value.Description;
appoint.Owner = value.Owner;
appoint.Priority = Convert.ToByte(value.Priority);
appoint.Recurrence = Convert.ToByte(value.Recurrence);
appoint.RecurrenceType
= value.RecurrenceType;
appoint.RecurrenceTypeCount = Convert.ToInt16(value.RecurrenceTypeCount);
appoint.Reminder = value.Reminder;
appoint.Categorize = value.Categorize;
appoint.AllDay = value.AllDay;
appoint.RecurrenceEndDate =
value.RecurrenceEndDate != null ? Convert.ToDateTime(value.RecurrenceEndDate).ToUniversalTime() :
endTime.ToUniversalTime();
appoint.RecurrenceStartDate
= value.RecurrenceStartDate != null ? Convert.ToDateTime(value.RecurrenceStartDate).ToUniversalTime() :
startTime.ToUniversalTime();
appoint.RecurrenceRule =
value.RecurrenceRule;
}
db.SubmitChanges();
}
IEnumerable data = new ScheduleDataDataContext().DefaultSchedules.Take(500); //
nw.Appointment.Take(5);
return Json(data, JsonRequestBehavior.AllowGet);
}
</Code>
We have prepared a sample, which
can be downloaded from the following location.
http://www.syncfusion.com/downloads/support/directtrac/general/ScheduleCRUD1171161275.zip
Please
let us know, if you need any further assistance on this.
Thanks
and Regards,
Krishna
Priya Sethuramalingam
Hi Mika,
Thank you for contacting Syncfusion support.
We were unable to reproduce the reported issue “Delete doesn’t work properly in CRUD operation” at our end. Normal CRUD operations are working properly when the appointment is created/edited/deleted and the same have prepared as the sample which can be downloaded from the following location:
http://www.syncfusion.com/downloads/support/forum/117672/ze/ScheduleCRUD1424964746
Regards,
Karthigeyan
Hi Karthigeyan,
Thank you for your support and another sample. Also that sample works great but unfortunately I couldn't solve my issue. There is some picture for explaining behaviour.
Following views show the parameters that controller gets:
Compared to other events and and samples, remove does not pass enough parameters. Reason probably lies somewhere in my code but I cannot figure out where :)
Best regards,
Mika