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.

Date difference while inserting appointment in schedule control

Thread ID:

Created:

Updated:

Platform:

Replies:

120541 Sep 24,2015 10:56 AM Sep 25,2015 05:30 AM ASP.NET MVC 1
loading
Tags: Schedule
saravanan
Asked On September 24, 2015 10:56 AM

Hi,

       I have used the below code to insert appointment

       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);

                DefaultSchedule appoint = new DefaultSchedule()

                {

                    Id = intMax + 1,

                    //StartTime = startTime,

                    //EndTime = endTime, 

                    StartTime = startTime.ToUniversalTime(),

                    EndTime = endTime.ToUniversalTime(),

                    Subject = value.Subject,

                    Description = value.Description,

                    AllDay = value.AllDay,

                    Recurrence = value.Recurrence,

                    RecurrenceRule = value.RecurrenceRule

                };

                db.DefaultSchedules.InsertOnSubmit(appoint);

                db.SubmitChanges();

            }


For example when i book an appointment for 24/9/2015 8.00 pm to 9.00 pm in the scheduler control, the appointment has been booked for that time.

But in db the  values inserted for starttime is 24/9/2015 9.00 pm and endtime is 10.00 pm and when i reload the page this booked appointment is not shown in 8.00 pm to 9.00 pm interval.

Instead  the appointment is shown in 2.30 pm to 3.30 pm interval.

could you suggest me what needs to be done to insert the actual timing in the db and get the actual timing when the scheduler is reloaded.

Thanks 
Saravanan .T

Karthigeyan Krishnamurthi [Syncfusion]
Replied On September 25, 2015 05:30 AM

Hi Saravanan,

Thanks for contacting Syncfusion Support.

We have prepared the sample to overcome the reported issue with the time difference while inserting appointments in schedule control which can be downloaded from the following location:


http://www.syncfusion.com/downloads/support/forum/120541/ze/ScheduleCRUD-1164979176


We request you to add StartTimeZone and EndTimeZone fields in database with the time zone value. You can mention the system timezone or any other timezone value in StartTimeZone and EndTimeZone field and based on the timezone value, the StartTime and EndTime of the appointment will be calculated internally and gets rendered in the Schedule. For example, “UTC +05:30” to the StartTimeZone and EndTimeZone field in the database (you can pass different TimeZone value to each field).Therefore, we request you to add and pass the TimeZone value in database to load the database appointments with the given time. Please find the following code snippets that we have used in the above sample to meet your requirement.

<code>

Index.cshtml

@(Html.EJ().Schedule("Schedule1")

        .Width("100%")

        .Height("525px")

        .TimeZone("UTC -05:00") // Here you can give your time zone value

        .CurrentDate(new DateTime(2015, 8, 24))

        .ShowCurrentTimeIndicator()

        .ShowQuickWindow(true)

          .AppointmentSettings(fields => fields.Datasource(ds => ds.URL("/Home/GetData").CrudURL("/Home/Batch").Adaptor("UrlAdaptor"))

            .Id("Id")

            .Subject("Subject")

            .StartTime("StartTime")

            .StartTimeZone("StartTimeZone")  // Kindly mention the StartTimeZone and EndTimeZone fields

            .EndTimeZone("EndTimeZone")

            .EndTime("EndTime")

            .Description("Description")

            .AllDay("AllDay")

            .Recurrence("Recurrence")

            .RecurrenceRule("RecurrenceRule"))
      )


HomeContorller.cs

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.Appointments.ToList().Count > 0 ? db.Appointments.ToList().Max(p => p.Id) : 1;

                DateTime startTime = Convert.ToDateTime(value.StartTime);

                DateTime endTime = Convert.ToDateTime(value.EndTime);

                var currentTimeZone = TimeZone.CurrentTimeZone;

                Appointment appoint = new Appointment()

                {

                    Id = value.Id,

                    StartTime = startTime, // Kindly ignore ToUniversalTime() for both Start and EndTime as we have internally processed the appointment to render in the same time as created(even after appointments are reloaded) by using StartTimeZone and EndTimeZone fields

                    EndTime = endTime,

                    StartTimeZone=value.StartTimeZone,

                    EndTimeZone=value.EndTimeZone,

                    Subject = value.Subject,                  

                    Description = value.Description,                   

                    Recurrence = value.Recurrence,

                    RoomId = value.RoomId,

                    OwnerId = value.OwnerId,

                    CategoryId = value.CategoryId,

                    AllDay = value.AllDay,                  

                    RecurrenceRule = value.RecurrenceRule,                   

                };

                db.Appointments.InsertOnSubmit(appoint);

                db.SubmitChanges();
            }

<code>

By default in schedule, appointments will render with the TimeZone “UTC +05:30”.  If the system TimeZone differs from the “UTC +05:30” or if different TimeZone is given on the sample side, it is mandatory to mention the “StartTimeZone and EndTimeZone” fields within the AppointmentSettings in order to save the appointments in the same time as created (even after appointments are reloaded). If the TimeZone value is given on sample side then the system TimeZone value will be neglected. For example “system TimeZone value/ sample side TimeZone value” is UTC +05:30 and if the “StarttimeZone and EndTimeZone value” is UTC +05:00 then the appointment will be rendered 30mins later from the time of appointment creation. The appointment will be rendered at 10.30 AM (say) if we create appointment at 10.00 AM.

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.

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.

;