Hi,
I have some app in MVC3 and I using Scheduler there. I’m using Timeline view, when I want to add some event to row for specific user on Y axis, that I can. But when I want to add another event which is on same or similar time (ex.: first event is from 10:00 to 15:00 and second I want 12:00 - 13:00) to same user, I can only click and drag new event, it doesn’t give me a window for fill items for new event… Nothing add into db… and this event disappear… Double click under first event not working too…
But, when I add event after first event (ex.: first is from 10:00 to 15:00 and second 16:00 to 20:00) it works fine.
Could you tell me where is a problem? I read a lot what is on scheduler-net.com but this I don’t understand why is not function…
I am sorry if this is very easy, I am a beginner in programming…
Code of View on Controller is this:
public ActionResult Scheduler()
{
var scheduler = new DHXScheduler(this);
scheduler.Data.Loader.PreventCache();
scheduler.LoadData = true;
scheduler.EnableDataprocessor = true;
scheduler.Localization.Directory = "locale";
scheduler.Localization.Set(SchedulerLocalization.Localizations.Czech);
scheduler.Calendars.AttachMiniCalendar();
scheduler.Config.xml_date = "%d/%m/%Y %H:%i";
scheduler.EnableDynamicLoading(SchedulerDataLoader.DynamicalLoadingMode.Day);
scheduler.Skin = DHXScheduler.Skins.Terrace;
scheduler.Extensions.Add(SchedulerExtensions.Extension.Recurring);
scheduler.XY.scroll_width = 0;
scheduler.Config.first_hour = 6;
scheduler.Config.last_hour = 21;
scheduler.Config.time_step = 30;
scheduler.Config.limit_time_select = true;
scheduler.Config.multi_day = true;
// Here I go into DB and get user for Y axis
using (var dbcontext = new AppDbContext())
var timeline = new TimelineView("timeline", "user_id");
var techniclist = dbcontext.Users.Where(x => x.Status == true).ToList();
timeline.FolderEventsAvailable = false;
timeline.FitEvents = false;
timeline.X_Unit = TimelineView.XScaleUnits.Week;
timeline.X_Date = "%j.%M";
timeline.X_Step = 1;
timeline.X_Size = 10;
timeline.X_Start = 1;
timeline.X_Length = 2;
timeline.AddSecondScale(TimelineView.XScaleUnits.Month, "%F %Y");
timeline.RenderMode = TimelineView.RenderModes.Bar;
timeline.SectionAutoheight = false;
foreach (var item in techniclist)
{
TimelineUnit section = new TimelineUnit(item.ID, item.Name + " " + item.Surname);
timeline.AddOption(section);
section.AddOption(item.ID);
}
scheduler.Views.Add(timeline);
timeline.AddOption(techniclist);
}
return View("Scheduler", scheduler);
}
Code of Data():
public ContentResult Data()
{
using (var dbcontext = new AppDbContext())
{
var filteredEvents = dbcontext.Events.Where(x => x.Status == true).ToList();
var events = filteredEvents.Select(s => new
{
id = s.id.ToString(),
user_id = s.UserID.ToString(),
text = s.text.ToString(),
start_date = s.start_date.ToString(),
end_date = s.end_date.ToString(),
event_length = s.event_length.HasValue ? s.event_length.ToString() : null,
event_pid = s.event_pid.HasValue ? s.event_pid.ToString() : null,
rec_type = s.rec_type != null ? s.rec_type.ToString() : null,
technic_id = s.technic_id != null ? s.technic_id.ToString() : null
});
var data = new SchedulerAjaxData(events);
return data;
}
}
And Save function on Controller:
public ActionResult Save(Events updatedEvent, FormCollection formData)
{
using (AppDbContext dbcontext = new AppDbContext())
{
var action = new DataAction(formData);
if (updatedEvent.rec_type == "none")
{
action.Type = DataActionTypes.Delete;
}
if (updatedEvent.rec_type == "null")
{
updatedEvent.rec_type = null;
}
if (action.Type == DataActionTypes.Insert)
{
if (IsAdmin == true)
{
int intuser = 0;
bool test = false;
test = Int32.TryParse(formData["user_id"], out intuser);
updatedEvent.UserID = intuser;
}
else
{
updatedEvent.UserID = LoggedUser.UserID;
updatedEvent.AdminEdit = false;
}
if (IsAdmin == true)
{
updatedEvent.AdminEdit = true;
}
dbcontext.Events.Add(updatedEvent);
}
if (action.Type == DataActionTypes.Update)
{
var dbEvent = dbcontext.Events.FirstOrDefault(x => x.id == updatedEvent.id);
if (dbEvent != null)
{
dbEvent.start_date = updatedEvent.start_date;
dbEvent.end_date = updatedEvent.end_date;
dbEvent.text = updatedEvent.text;
dbEvent.rec_type = updatedEvent.rec_type;
dbEvent.event_length = updatedEvent.event_length;
dbEvent.event_pid = updatedEvent.event_pid;
dbEvent.technic_id = updatedEvent.technic_id;
dbcontext.Entry(dbEvent).State = EntityState.Modified;
}
}
if (action.Type == DataActionTypes.Delete)
{
var dbEvent = dbcontext.Events.FirstOrDefault(x => x.id == updatedEvent.id);
if (dbEvent != null)
{
dbcontext.Events.Remove(dbEvent);
}
}
dbcontext.SaveChanges();
action.TargetId = updatedEvent.id;
return (new AjaxSaveResponse(action));
}
}
And View with scheduler:
@model DHTMLX.Scheduler.DHXScheduler
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
@*Some HTML code here*@
@Html.Raw(Model.Render())
Thanks for help to everyone!