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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Schedule bind to viewmodel

Thread ID:

Created:

Updated:

Platform:

Replies:

129804 Apr 4,2017 03:37 PM UTC Jul 7,2017 09:09 AM UTC ASP.NET Core 3
loading
Tags: Schedule
dsapo
Asked On April 4, 2017 03:37 PM UTC

Hi Support:

Currently I have my schedule control bound to a datamanager as follows:

 <e-datamanager url="GetData" adaptor="UrlAdaptor"></e-datamanager>

Would be possible to bind the schedule control a viewmodel class.

Thanks in advanced.

David

Karthigeyan Krishnamurthi [Syncfusion]
Replied On April 6, 2017 12:14 PM UTC

Hi David,   
   
Thank you for contacting Syncfusion support. 
       
We have prepared the sample to render the appointments using view model concept which can be download from the below location. 
 
Kindly refer the below code example used in the sample. 
 
<Code> 
<ej-schedule id="Schedule1" width="100%" height="525px" create="onCreate" current-date="new DateTime(2016, 6, 2)"> 
    <e-appointment-settings  apply-time-offset="false" id="Id" subject='"Subject"' start-time='"StartTime"' end-time='"EndTime"' all-day='"AllDay"' recurrence='"Recurrence"' recurrence-rule='"RecurrenceRule"'> 
        <e-datamanager id="Data" json="(IEnumerable<Schedule1.Controllers.HomeController.ScheduleData>)ViewBag.datasource"></e-datamanager>         
    </e-appointment-settings> 
</ej-schedule> 
</Code> 
 
Regards, 
Karthigeyan 





                                                     


Leon
Replied On July 6, 2017 05:03 PM UTC

I am trying this sample and getting the data works just fine. But when I try this code:

<e-datamanager json="(IEnumerable<object>)Model" update-url="/Processes/Edit" insert-url="/Processes/Create" remove-url="/Processes/Delete" adaptor="remoteSaveAdaptor" /> 

the events are not getting fired on the server side. Do you have  sample of remoteSaveAdaptor editing an entry?



Karthigeyan Krishnamurthi [Syncfusion]
Replied On July 7, 2017 09:09 AM UTC

Hi Juan, 
 
We recommend you to use UrlAdaptor to perform CRUD operation with in Scheduler and for the same we have prepared the sample which can be download form the below location. 
 
<Code> 
<ej-schedule id="Schedule1" width="100%" height="525px" current-date="new DateTime(2014, 12, 5)"> 
    <e-appointment-settings apply-time-offset="false" id="Id" subject='"Subject"' start-time='"StartTime"' end-time='"EndTime"' all-day='"AllDay"' recurrence='"Recurrence"' recurrence-rule='"RecurrenceRule"'> 
        <e-datamanager url="Home/GetData" crud-url="Home/Batch" adaptor="UrlAdaptor"></e-datamanager> 
    </e-appointment-settings> 
</ej-schedule> 
 
public List<DefaultSchedule> Batch([FromBody] EditParams param) 
{ 
    if (param.action == "insert" || (param.action == "batch" && (param.added.Count>0))) // this block of code will execute while inserting the appointments 
    { 
        DefaultSchedule appoint = new DefaultSchedule(); 
        object result; 
        if (param.action == "insert") 
        { 
            var value = param.value; 
            foreach (var fieldName in value.GetType().GetProperties()) 
            { 
                var newName = fieldName.ToString().Split(null); 
                if (newName[1] == "Id") result = (_context.DefaultSchedule.ToList().Count > 0 ? _context.DefaultSchedule.ToList().Max(p => p.Id) : 1) + 1; 
                else if (newName[1] == "StartTime" || newName[1] == "EndTime") result = Convert.ToDateTime(fieldName.GetValue(value)); 
                else result = fieldName.GetValue(value); 
                fieldName.SetValue(appoint, result); 
            } 
            _context.DefaultSchedule.Add(appoint); 
        } 
        else 
        { 
            foreach (var item in param.added.Select((x, i) => new { Value = x, Index = i })) 
            { 
                var value = item.Value; 
                foreach (var fieldName in value.GetType().GetProperties()) 
                { 
                    var newName = fieldName.ToString().Split(null); 
                    if (newName[1] == "Id") result = (_context.DefaultSchedule.ToList().Count > 0 ? _context.DefaultSchedule.ToList().Max(p => p.Id) : 1) + 1 + 
                    else if (newName[1] == "StartTime" || newName[1] == "EndTime") result = Convert.ToDateTime(fieldName.GetValue(value)); 
                    else result = fieldName.GetValue(value); 
                    fieldName.SetValue(appoint, result); 
                } 
                _context.DefaultSchedule.Add(appoint); 
            } 
        } 
        _context.SaveChanges(); 
    } 
    if ((param.action == "remove") || (param.action == "batch" && (param.deleted.Count > 0))) // this block of code will execute while removing the appointment 
    { 
        if (param.action == "remove") 
        { 
            DefaultSchedule app = _context.DefaultSchedule.Where(c => c.Id == Convert.ToInt32(param.key)).FirstOrDefault(); 
            if (app != null) _context.DefaultSchedule.Remove(app); 
        } 
        else 
        { 
            foreach (var a in param.deleted) 
            { 
                var app = _context.DefaultSchedule.ToList().Where(c => c.Id == Convert.ToInt32(a.Id)).FirstOrDefault(); 
                if (app != null) _context.DefaultSchedule.Remove(app); 
            } 
        } 
        _context.SaveChanges(); 
    } 
    if (param.action == "update" || (param.action == "batch" && (param.changed.Count > 0))) // this block of code will execute while updating the appointment 
    { 
        var value = param.action == "update" ? param.value : param.changed[0]; 
        var filterData = _context.DefaultSchedule.Where(c => c.Id == Convert.ToInt32(value.Id)); 
        if (filterData.Count() > 0) 
        { 
            DefaultSchedule appoint = _context.DefaultSchedule.Single(A => A.Id == Convert.ToInt32(value.Id)); 
            appoint.StartTime = Convert.ToDateTime(value.StartTime); 
            appoint.EndTime = Convert.ToDateTime(value.EndTime); 
            appoint.Subject = value.Subject; 
            appoint.Recurrence = value.Recurrence; 
            appoint.AllDay = value.AllDay; 
            appoint.RecurrenceRule = value.RecurrenceRule; 
        } 
        _context.SaveChanges(); 
    } 
    List<DefaultSchedule> datas = _context.DefaultSchedule.Take(500).ToList(); 
    return datas; 
} 
 
</Code> 
 
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

;