public List <ScheduleSlot> SplitIntoGroupsOf(int count) { // output List <ScheduleSlot> output = new List <ScheduleSlot>(); // figure out how many times we need to loop int loopTimes = (this.Assigned.Count > this.EmployeeNeededCount) ? this.Assigned.Count : this.EmployeeNeededCount; for (int x = 0; x < loopTimes;) { // create new object ScheduleSlot splitOne = new ScheduleSlot(this.Name, this.Day, this.Start, this.End, 0, this.Date); // check how if we need to add names if (x < this._assigned.Count) { splitOne._assigned.Add(this._assigned[x]); } splitOne._peopleNeeded++; //increment x++; // check if count is too high if (x >= loopTimes) { output.Add(splitOne); break; } // check again and add if needed if (x < this._assigned.Count) { splitOne._assigned.Add(this._assigned[x]); } splitOne._peopleNeeded++; x++; // add to output output.Add(splitOne); } return(output); }
/// <summary> /// adds new shift in ordered form. /// </summary> /// <param name="shift">new shift.</param> public void AddInOrder(ScheduleSlot shift) { // case 1 - no other shifts added for this day yet, just add it if (this._shifts[shift._shiftInfo.Day].Count == 0) { this._shifts[shift._shiftInfo.Day].Add(shift); this._count++; return; } // case 2 - shifts already exist int insertAt = -1; // go through each element until we find the position to insert at foreach (ScheduleSlot existing in this._shifts[shift._shiftInfo.Day]) { // check if new shift is earlier than existing if (TimeUtilities.IsEarlier(shift, existing)) { insertAt = this._shifts[shift._shiftInfo.Day].IndexOf(existing); break; } } // check if we found place to insert at if (insertAt == -1) { // insert at end, all exisiting shifts are earlier than this one this._shifts[shift._shiftInfo.Day].Add(shift); this._count++; } else { // found somewhere to insert at and insert there. this._shifts[shift._shiftInfo.Day].Insert(insertAt, shift); this._count++; } }
/// <summary> /// check we contain this shift. /// </summary> /// <param name="target">Shift to find.</param> /// <returns></returns> public bool Contains(ScheduleSlot target) { return(this.Contains(target._shiftInfo.Day, target._shiftInfo.Name)); }
/// <summary> /// removes a specified shift from dictionary. /// </summary> /// <param name="target"></param> public void Remove(ScheduleSlot target) { this._shifts[target.Day].Remove(target); }
/// <summary> /// Add a new shift to end of list. /// </summary> /// <param name="shift">new shift.</param> public void Add(ScheduleSlot shift) { this._shifts[shift._shiftInfo.Day].Add(shift); }
/// <summary> /// Loads scheduleslot by copying an old one /// </summary> /// <param name="copyThis">Existing object to copy</param> public ScheduleSlot(ScheduleSlot copyThis) { Load(copyThis._peopleNeeded, copyThis.Unassigned, copyThis.Assigned); LoadStruct(copyThis.Name, copyThis.Day, copyThis.Start, copyThis.End, copyThis.Date); }