BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
We are using the schedule control with EJ2 MVC and we want load data dynamically into the control as the user changes months.
Is there a way to accomplish this? Please advance, thx.
KennethT
public JsonResult LoadData(Params param) // Here we get the Start and End Date and based on that can filter the data and return to Scheduler
{
DateTime start = param.StartDate;
DateTime end = param.EndDate;
var data = db.ScheduleEventDatas.Where(app => (app.StartTime >= start && app.StartTime <= end) || (app.RecurrenceRule != null && app.RecurrenceRule !="")).ToList(); // Here filtering the events based on the start and end date value.
return Json(data, JsonRequestBehavior.AllowGet);
}
public class Params
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
} |
@Html.EJS().Schedule("schedule").Width("100%").Height("650px").CssClass("block-events").Views(view => { view.Option(View.Day).Add(); view.Option(View.TimelineDay).Add(); view.Option(View.TimelineMonth).Add(); }).CurrentView(View.TimelineDay).SelectedDate(new DateTime(2018, 8, 1)).EventSettings(es => es.DataSource(dataManger =>
{
dataManger.Url("/Home/LoadData").CrudUrl("/Home/UpdateData").CrossDomain(true).Adaptor("UrlAdaptor");
})).Render()
public JsonResult LoadData(Params param) // Here we get the Start and End Date and based on that can filter the data and return to Scheduler
{
DateTime start = param.StartDate;
DateTime end = param.EndDate;
var data = db.ScheduleEventDatas.Where(app => (app.StartTime >= start && app.StartTime <= end) || (app.RecurrenceRule != null && app.
return Json(data, JsonRequestBehavior.AllowGet);
} |
<EjsSchedule TValue="AppointmentData" Height="550px" CurrentView="View.Week" SelectedDate="@(new DateTime(2018, 4, 19))">
<ScheduleEventSettings TValue="AppointmentData">
<EjsDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></EjsDataManager>
</ScheduleEventSettings>
</EjsSchedule>
@code {
static HttpClient client = new HttpClient();
public class CustomAdaptor : DataAdaptor
{
public async override Task<object> ReadAsync(DataManagerRequest dataManagerRequest, string key = null)
{
AppointmentData[] datasource = JsonConvert.DeserializeObject<AppointmentData[]>(json);
return dataManagerRequest.RequiresCounts ? new DataResult() { Result = datasource, Count = datasource.Count() } : (object)datasource;
}
public async override Task<object> InsertAsync(DataManager dataManager, object data, string key)
{
AppointmentData insertData = data as AppointmentData;
var formContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("Id", insertData.Id.ToString()),
new KeyValuePair<string, string>("Subject", insertData.Subject),
new KeyValuePair<string, string>("StartTime", insertData.StartTime.ToString()),
new KeyValuePair<string, string>("EndTime", insertData.EndTime.ToString()),
new KeyValuePair<string, string>("RecurrenceID", insertData.RecurrenceID.ToString()),
new KeyValuePair<string, string>("RecurrenceRule", insertData.RecurrenceRule),
new KeyValuePair<string, string>("RecurrenceException", insertData.RecurrenceException),
new KeyValuePair<string, string>("IsAllDay", insertData.IsAllDay.ToString())
});
return data;
}
public async override Task<object> UpdateAsync(DataManager dataManager, object data, string keyField, string key)
{
AppointmentData updateData = data as AppointmentData;
var formContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("Id", updateData.Id.ToString()),
new KeyValuePair<string, string>("Subject", updateData.Subject),
new KeyValuePair<string, string>("StartTime", updateData.StartTime.ToString()),
new KeyValuePair<string, string>("EndTime", updateData.EndTime.ToString()),
new KeyValuePair<string, string>("RecurrenceID", updateData.RecurrenceID.ToString()),
new KeyValuePair<string, string>("RecurrenceRule", updateData.RecurrenceRule),
new KeyValuePair<string, string>("RecurrenceException", updateData.RecurrenceException),
new KeyValuePair<string, string>("IsAllDay", updateData.IsAllDay.ToString())
});
return data;
}
public async override Task<object> RemoveAsync(DataManager dataManager, object data, string keyField, string key) //triggers on appointment deletion through public method DeleteEvent
{
var json = await client.DeleteAsync(uri);
return data;
}
public async override Task<object> BatchUpdateAsync(DataManager dataManager, object changedRecords, object addedRecords, object deletedRecords, string keyField, string key)
{
object records = deletedRecords;
List<AppointmentData> deleteData = deletedRecords as List<AppointmentData>;
foreach (var data in deleteData)
{
var json = await client.DeleteAsync(uri);
records = deletedRecords;
}
List<AppointmentData> addData = addedRecords as List<AppointmentData>;
foreach (var data in addData)
{
var formContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("Id", data.Id.ToString()),
new KeyValuePair<string, string>("Subject", data.Subject),
new KeyValuePair<string, string>("StartTime", data.StartTime.ToString()),
new KeyValuePair<string, string>("EndTime", data.EndTime.ToString()),
new KeyValuePair<string, string>("RecurrenceID", data.RecurrenceID.ToString()),
new KeyValuePair<string, string>("RecurrenceRule", data.RecurrenceRule),
new KeyValuePair<string, string>("RecurrenceException", data.RecurrenceException),
new KeyValuePair<string, string>("IsAllDay", data.IsAllDay.ToString())
});
records = addedRecords;
}
List<AppointmentData> updateData = changedRecords as List<AppointmentData>;
foreach (var data in updateData)
{
var formContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("Id", data.Id.ToString()),
new KeyValuePair<string, string>("Subject", data.Subject),
new KeyValuePair<string, string>("StartTime", data.StartTime.ToString()),
new KeyValuePair<string, string>("EndTime", data.EndTime.ToString()),
new KeyValuePair<string, string>("RecurrenceID", data.RecurrenceID.ToString()),
new KeyValuePair<string, string>("RecurrenceRule", data.RecurrenceRule),
new KeyValuePair<string, string>("RecurrenceException", data.RecurrenceException),
new KeyValuePair<string, string>("IsAllDay", data.IsAllDay.ToString())
});
records = changedRecords;
}
return records;
}
}
}
|
public ScheduleDataContext _context = new ScheduleDataContext();
//// GET: api/<controller>
[HttpGet]
public IEnumerable<AppointmentData> Get()
{
return _context.AppointmentData.ToList();
}
[HttpPost]
public void Post(AppointmentData appointmentData)
{
appointmentData.Id = Convert.ToInt32(appointmentData.Id);
appointmentData.StartTime = Convert.ToDateTime(appointmentData.StartTime);
appointmentData.EndTime = Convert.ToDateTime(appointmentData.EndTime);
appointmentData.IsAllDay = Convert.ToBoolean(appointmentData.IsAllDay);
_context.AppointmentData.Add(appointmentData);
_context.SaveChanges();
}
// PUT api/<controller>/5
[HttpPut]
public void Put(string id, AppointmentData appointmentData)
{
AppointmentData updateData = _context.AppointmentData.First(i => i.Id == Convert.ToInt32(id));
updateData.Subject = appointmentData.Subject;
updateData.StartTime = Convert.ToDateTime(appointmentData.StartTime);
updateData.EndTime = Convert.ToDateTime(appointmentData.EndTime);
updateData.IsAllDay = Convert.ToBoolean(appointmentData.IsAllDay);
updateData.RecurrenceException = appointmentData.RecurrenceException;
updateData.RecurrenceRule = appointmentData.RecurrenceRule;
_context.AppointmentData.Update(updateData);
_context.SaveChanges();
}
// DELETE api/<controller>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
AppointmentData deleteData = _context.AppointmentData.First(i => i.Id == id);
_context.AppointmentData.Remove(deleteData);
_context.SaveChanges();
} |