public void Remove(QueueRunner selectedItem) { //Placeholder var helper = QueueRunners.ToList(); var helper2 = new List <QueueRunner>(); helper.Remove(selectedItem); //Clear and update plus update position QueueRunners.Clear(); int i = 0; foreach (var item in helper) { item.Position = i + 1; helper2.Add(item); //QueueRunners.Add(item); i++; } //Update database DataService.UpdateQueueAsync(helper2); DataService.RemoveFromQueueAsync(selectedItem); UpdateCollections(); }
public void MoveDown(QueueRunner selectedItem) { var index = selectedItem.Position; //Bound check if (index >= QueueRunners.Count) { return; } //Placeholders var helper = QueueRunners.ToList(); var other = helper[index]; //Switch positions selectedItem.Position += 1; other.Position -= 1; //Switch indexes in List helper[selectedItem.Position - 1] = selectedItem; helper[other.Position - 1] = other; ////Clear and update //QueueRunners.Clear(); //foreach (var item in helper) //{ // QueueRunners.Add(item); //} //Update database DataService.UpdateQueueAsync(helper); UpdateCollections(); }
//do not use Refresh or implement AllQueueRunners (use it like updatecollections) public void Refresh() { var helper = QueueRunners.ToList().OrderBy(x => x.Position); QueueRunners.Clear(); foreach (var item in helper) { QueueRunners.Add(item); } }
public void QueueNextRunner(TimeSpan ts) { //Update all position in the queue var helper = QueueRunners.ToList(); foreach (var item in helper) { item.Position -= 1; } //Register run and Update database if (CurrentRunner != null && helper.Count() != 0) { //Update database DataService.UpdateQueueAsync(helper); RegisterRun(ts); DataService.RemoveFromQueueAsync(CurrentRunner); } UpdateCollections(); }