apply-time-offset in ASP.NET MVC?

Hello,

Is there an apply-time-offset equivalent in ASP.NET MVC?  I want to be able to show events in the calendar at the same time as they are in the database regardless of what time zone I'm in.  I feel like the solution offered here: https://www.syncfusion.com/forums/129809/avoid-using-timezones-and-dst-in-the-schedule with regards to apply-time-offset might be what I'm looking for but the EJS().Schedule control doesn't seem to have that as an option.  Using Syncfusion.EJ2 18.34.

Thanks.

1 Reply 1 reply marked as answer

RV Ravikumar Venkatesan Syncfusion Team January 15, 2021 03:45 PM UTC

Hi Edward, 
  
Greetings from Syncfusion support. 
  
We have validated your query at our end and achieve d it using actionBegin and dataBinding event of the Schedule and for the same, we have prepared a sample which can be downloaded from the below link. 
  
  
[Index.cshtml] 
<div> 
    @(Html.EJS().Schedule("schedule") 
        .Width("100%") 
        .Height("550px") 
        .SelectedDate(new DateTime(2021, 1, 14)) 
        .Timezone("America/Chicago") 
        .ActionBegin("onActionBegin") 
        .DataBinding("OnDataBinding") 
        .EventSettings(es => es.DataSource(dataManager => dataManager.Url("/Home/LoadData").CrudUrl("/Home/UpdateData").CrossDomain(true).Adaptor("UrlAdaptor")) 
        ).Render() 
    ) 
</div> 
  
<script type="text/javascript"> 
    function onActionBegin(args) { 
        if (["eventCreate", "eventChange"].indexOf(args.requestType) > -1) { 
            var datas = [...args.addedRecords, ...args.changedRecords]; 
            for (var a = 0; a < datas.length; a++) { 
                var data = datas[a]; 
                // Adding the actual event start time and end time to the custom event fields 
                data.CustomStart = data.StartTime; 
                data.CustomEnd = data.EndTime; 
            } 
        } 
    } 
    function OnDataBinding(args) { 
        let result = args.result; 
        let finalResult = []; 
        var scheduleObj = document.querySelector('.e-schedule').ej2_instances[0]; 
        let localTimezoneName = scheduleObj.tzModule.getLocalTimezoneName(); 
        for (let i = 0; i < result.length; i++) { 
            let data = result[i]; 
            // Converting the events start and end time based on the event start and end time zones on data bind with the Schedule 
            data.StartTime = scheduleObj.tzModule.convert(args.result[i].StartTime, args.result[i].StartTimezone, localTimezoneName); 
            data.EndTime = scheduleObj.tzModule.convert(args.result[i].EndTime, args.result[i].EndTimezone, localTimezoneName); 
            finalResult.push(data); 
        } 
        args.result = finalResult; 
    } 
</script> 
  
[HomeController.cs] 
        public JsonResult UpdateData(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.ScheduleEventDatas.ToList().Count > 0 ? db.ScheduleEventDatas.ToList().Max(p => p.Id) : 1; 
                // Adding the custom field start and end time fields values to the StartTime and EndTime fields 
                DateTime startTime = Convert.ToDateTime(value.CustomStart); 
                DateTime endTime = Convert.ToDateTime(value.CustomEnd); 
                ScheduleEventData appointment = new ScheduleEventData() 
                { 
                    Id = intMax + 1, 
                    StartTime = startTime.ToLocalTime(), 
                    EndTime = endTime.ToLocalTime(), 
                    Subject = value.Subject, 
                    StartTimezone = value.StartTimezone, 
                    EndTimezone = value.EndTimezone 
                }; 
                db.ScheduleEventDatas.InsertOnSubmit(appointment); 
                db.SubmitChanges(); 
            } 
            if (param.action == "update" || (param.action == "batch" && param.changed != null)) // this block of code will execute while updating the appointment 
            { 
                var value = (param.action == "update") ? param.value : param.changed[0]; 
                var filterData = db.ScheduleEventDatas.Where(c => c.Id == Convert.ToInt32(value.Id)); 
                if (filterData.Count() > 0) 
                { 
                    // Adding the custom field start and end time fields values to the StartTime and EndTime fields 
                    DateTime startTime = Convert.ToDateTime(value.CustomStart); 
                    DateTime endTime = Convert.ToDateTime(value.CustomEnd); 
                    ScheduleEventData appointment = db.ScheduleEventDatas.Single(A => A.Id == Convert.ToInt32(value.Id)); 
                    appointment.StartTime = startTime.ToLocalTime(); 
                    appointment.EndTime = endTime.ToLocalTime(); 
                    appointment.Subject = value.Subject; 
                    appointment.StartTimezone = value.StartTimezone; 
                    appointment.EndTimezone = value.EndTimezone; 
                } 
                db.SubmitChanges(); 
            } 
            var data = db.ScheduleEventDatas.ToList(); 
            return Json(data, JsonRequestBehavior.AllowGet); 
        }        
  
Kindly try the above sample and get back to us if you need any further assistance. 
  
Regards, 
Ravikumar Venkatesan 


Marked as answer
Loader.
Up arrow icon