- Home
- Forum
- ASP.NET Core
- Schedule bind to viewmodel
Schedule bind to viewmodel
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
SIGN IN To post a reply.
3 Replies
KK
Karthigeyan Krishnamurthi
Syncfusion Team
April 6, 2017 12:14 PM UTC
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
LE
Leon
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?
KK
Karthigeyan Krishnamurthi
Syncfusion Team
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
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
DS dsapo
- Apr 4, 2017 03:37 PM UTC
- Jul 7, 2017 09:09 AM UTC