We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Scheduler Implementation

Thread ID:

Created:

Updated:

Platform:

Replies:

117672 Nov 26,2014 10:35 AM UTC Nov 20,2015 06:23 AM UTC ASP.NET MVC 8
loading
Tags: Schedule
ezequie da silva daniel
Asked On November 26, 2014 10:35 AM UTC

Hello,

I have doubts on how to use the Scheduler control writing data in the database, I consulted the online technical material and the forum, do not understand how the modal window in the bank writes the database, in SQl Server for example.

Krishna Priya Sethuramalingam [Syncfusion]
Replied On November 27, 2014 12:43 PM UTC

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

 

 


Mika Kahilainen
Replied On November 9, 2015 09:19 AM UTC

Hello,

This is a good example and I managed to save appointments into MySQL table. But delete doesn't work. Controller receives parameters, but they seem unvalid: param.action is "remove" but rest of paramters are null. What should be checked?

Karthigeyan Krishnamurthi [Syncfusion]
Replied On November 10, 2015 11:17 AM UTC

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


Mika Kahilainen
Replied On November 10, 2015 10:26 PM UTC

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.


view

Following views show the parameters that controller gets:

create

edit

remove


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

Mika Kahilainen
Replied On November 10, 2015 10:33 PM UTC

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.


view

Following views show the parameters that controller gets:

create

edit

remove


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

Pictures should be seen here:

view

create

Edit

remove

Srinivasan N [Syncfusion]
Replied On November 11, 2015 01:34 PM UTC

Hi Mika,

Thanks for the update.

we were still unable to reproduce the reported issue. Could you please tell us the Syncfusion DLL version that you are using in your application? If possible please revert back the provided sample based on your application along with the replication procedure to reproduce the issue at our end. This would be more helpful for us to  investigate further and provide a solution at the earliest
Please let us know if you have any concerns.

Regards,
Srinivasan N

Mika Kahilainen
Replied On November 19, 2015 10:56 AM UTC

Hi!

Dll versions are:
runtime version v4.0.30319
version 13.3400.0.7

I will try to send a sample also.

WBR,
Mika

Karthigeyan Krishnamurthi [Syncfusion]
Replied On November 20, 2015 06:23 AM UTC

Hi Mika,

Thanks for your update.

We have checked the reported scenario in the sample (provided in our past update) with the mentioned DLL version and were unable to reproduce the issue, “Delete not working properly” at our end. We will wait for your sample to investigate further and provide a solution at the earliest.

Regards,
Karthigeyan



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;