Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult SchedulerActive()
- {
- return new Dps().CallBack(this);
- }
- class Dps : DayPilotScheduler
- {
- CalendarContext dc = new CalendarContext();
- protected override void OnInit(InitArgs e)
- {
- LoadResources();
- Update(CallBackUpdateType.Full);
- }
- private void LoadResources()
- {
- List<Position> dbPositions = (from Positions in dc.Positions select Positions).ToList();
- foreach (var Position in dbPositions)
- {
- Resource r = new Resource(Position.PositionName, Position.PositionID.ToString());
- Resources.Add(r);
- }
- }
- protected override void OnEventResize(EventResizeArgs e)
- {
- int EventID = Convert.ToInt32(e.Id);
- WorkScheduler ws = dc.WorkSchedulers.Where(x => x.WorkSchedulerID == EventID).FirstOrDefault();
- ws.PlanStart = e.NewStart;
- ws.PlanEnd = e.NewEnd;
- dc.Entry(ws).State = EntityState.Modified;
- dc.SaveChanges();
- UpdateWithMessage("The event was resized.");
- }
- protected override void OnEventMove(EventMoveArgs e)
- {
- int EventID = Convert.ToInt32(e.Id);
- int ResourceID = Convert.ToInt32(e.NewResource);
- Position p = dc.Positions.Where(x => x.PositionID == ResourceID).FirstOrDefault();
- dc.WorkSchedulers.Include("Positions").FirstOrDefault(z => z.WorkSchedulerID == EventID).Positions.Add(p);
- dc.SaveChanges();
- UpdateWithMessage("The event was moved.");
- }
- protected override void OnEventDelete(EventDeleteArgs e)
- {
- int EventID = Convert.ToInt32(e.Id);
- int ResourceID = Convert.ToInt32(e.Resource);
- Position p = dc.Positions.Where(x => x.PositionID == ResourceID).FirstOrDefault();
- dc.WorkSchedulers.Include("Positions").FirstOrDefault(z => z.WorkSchedulerID == EventID).Positions.Remove(p);
- dc.SaveChanges();
- UpdateWithMessage("An event was deleted.");
- }
- protected override void OnCommand(CommandArgs e)
- {
- switch (e.Command)
- {
- case "refresh":
- Update();
- break;
- }
- }
- protected override void OnFinish()
- {
- if (UpdateType == CallBackUpdateType.None)
- {
- return;
- }
- List<WorkSchedulerPositionViewModel> x =
- (from WS in dc.WorkSchedulers
- from P in WS.Positions
- where !((WS.PlanEnd <= VisibleStart) || (WS.PlanStart >= VisibleEnd))
- select new WorkSchedulerPositionViewModel
- {
- EventID = WS.WorkSchedulerID,
- DataStart = (DateTime)WS.PlanStart,
- DataEnd = (DateTime)WS.PlanEnd,
- Person = WS.PaintballWorker.User.Username,
- Resource = P.PositionID
- }).ToList();
- Events = x.AsEnumerable();
- DataIdField = "EventID";
- DataTextField = "Person";
- DataStartField = "DataStart";
- DataEndField = "DataEnd";
- DataResourceField = "Resource";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement