Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.79 KB | None | 0 0
  1.     public ActionResult SchedulerActive()
  2.         {
  3.             return new Dps().CallBack(this);
  4.         }
  5.  
  6.         class Dps : DayPilotScheduler
  7.         {
  8.             CalendarContext dc = new CalendarContext();
  9.  
  10.             protected override void OnInit(InitArgs e)
  11.             {
  12.                 LoadResources();
  13.                 Update(CallBackUpdateType.Full);
  14.             }
  15.  
  16.             private void LoadResources()
  17.             {
  18.                 List<Position> dbPositions = (from Positions in dc.Positions select Positions).ToList();
  19.                 foreach (var Position in dbPositions)
  20.                 {
  21.                     Resource r = new Resource(Position.PositionName, Position.PositionID.ToString());
  22.                     Resources.Add(r);
  23.                 }
  24.             }
  25.  
  26.             protected override void OnEventResize(EventResizeArgs e)
  27.             {
  28.                 int EventID = Convert.ToInt32(e.Id);
  29.                 WorkScheduler ws = dc.WorkSchedulers.Where(x => x.WorkSchedulerID == EventID).FirstOrDefault();
  30.                 ws.PlanStart = e.NewStart;
  31.                 ws.PlanEnd = e.NewEnd;
  32.                 dc.Entry(ws).State = EntityState.Modified;
  33.                 dc.SaveChanges();
  34.                 UpdateWithMessage("The event was resized.");
  35.             }
  36.  
  37.             protected override void OnEventMove(EventMoveArgs e)
  38.             {
  39.                 int EventID = Convert.ToInt32(e.Id);
  40.                 int ResourceID = Convert.ToInt32(e.NewResource);
  41.                 Position p = dc.Positions.Where(x => x.PositionID == ResourceID).FirstOrDefault();            
  42.                 dc.WorkSchedulers.Include("Positions").FirstOrDefault(z => z.WorkSchedulerID == EventID).Positions.Add(p);
  43.                 dc.SaveChanges();
  44.                 UpdateWithMessage("The event was moved.");
  45.             }
  46.  
  47.             protected override void OnEventDelete(EventDeleteArgs e)
  48.             {
  49.                 int EventID = Convert.ToInt32(e.Id);
  50.                 int ResourceID = Convert.ToInt32(e.Resource);
  51.                 Position p = dc.Positions.Where(x => x.PositionID == ResourceID).FirstOrDefault();
  52.                 dc.WorkSchedulers.Include("Positions").FirstOrDefault(z => z.WorkSchedulerID == EventID).Positions.Remove(p);
  53.                 dc.SaveChanges();
  54.                 UpdateWithMessage("An event was deleted.");
  55.             }
  56.             protected override void OnCommand(CommandArgs e)
  57.             {
  58.                 switch (e.Command)
  59.                 {
  60.                     case "refresh":
  61.                         Update();
  62.                         break;
  63.                 }
  64.             }
  65.  
  66.             protected override void OnFinish()
  67.             {
  68.                 if (UpdateType == CallBackUpdateType.None)
  69.                 {
  70.                     return;
  71.                 }
  72.                 List<WorkSchedulerPositionViewModel> x =
  73.                         (from WS in dc.WorkSchedulers
  74.                          from P in WS.Positions
  75.                          where !((WS.PlanEnd <= VisibleStart) || (WS.PlanStart >= VisibleEnd))
  76.                          select new WorkSchedulerPositionViewModel
  77.                          {
  78.                              EventID = WS.WorkSchedulerID,
  79.                              DataStart = (DateTime)WS.PlanStart,
  80.                              DataEnd = (DateTime)WS.PlanEnd,
  81.                              Person = WS.PaintballWorker.User.Username,
  82.                              Resource = P.PositionID
  83.                          }).ToList();
  84.                 Events = x.AsEnumerable();
  85.  
  86.                 DataIdField = "EventID";
  87.                 DataTextField = "Person";
  88.                 DataStartField = "DataStart";
  89.                 DataEndField = "DataEnd";
  90.                 DataResourceField = "Resource";
  91.             }
  92.         }
  93.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement