public void CheckRaceFinished(Track track) { if (_participantsCounter == 0 && track != null) { NextRace?.Invoke(this, new EventArgs()); } }
public ActionResult DeleteConfirmed(int id) { NextRace nextRace = db.NextRaces.Find(id); db.NextRaces.Remove(nextRace); db.SaveChanges(); return(RedirectToAction("Index")); }
//Stop the race public void Stop() { Timer.Enabled = false; //Remove all excisting references CleanReferences(); //Set the Nextrace as currentrace in Data Data.NextRace(); //Invoke next race with the new race as parameter NextRace.Invoke(this, new RaceStartEventArgs(Data.CurrentRace)); }
public ActionResult Create([Bind(Include = "EFKey,RunnerId,Distance,Time,Active")] NextRace nextRace) { if (ModelState.IsValid) { db.NextRaces.Add(nextRace); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RunnerId = new SelectList(db.runners, "EFKey", "firstname", nextRace.RunnerId); return(View(nextRace)); }
// GET: NextRaces/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } NextRace nextRace = db.NextRaces.Find(id); if (nextRace == null) { return(HttpNotFound()); } return(View(nextRace)); }
public ActionResult NewTarget(string distances) { db.NextRaces.RemoveRange(db.NextRaces); var allRunners = db.runners.Include(n => n.LastRaces); // foreach runner foreach (var r in allRunners) { var lastRace = r.LastRaces.FirstOrDefault(s => s.RunnerId == r.EFKey); if (lastRace != null) { var oldDistance = lastRace.Distance; var oldtime = lastRace.Time; var predictedTime = (RaceCalc.calcPredictedTime(oldDistance, Convert.ToDouble(distances), oldtime) + RaceCalc.cameron(oldDistance, Convert.ToDouble(distances), oldtime)) / 2; RunningModel.NextRace nextrace = new NextRace(); nextrace.RunnerId = r.EFKey; nextrace.Distance = Convert.ToDouble(distances); nextrace.Time = Convert.ToInt32(predictedTime); nextrace.Active = true; db.NextRaces.Add(nextrace); } } db.SaveChanges(); // get last race time and distance // calculate next time for next time // update next date time and distance // contruct view model to display new times. var allNextRaces = db.NextRaces; List <nextRaceVM> vm = new List <nextRaceVM>(); foreach (var m in allNextRaces) { var nr = new nextRaceVM(); var last = db.LastRaces.SingleOrDefault(l => l.RunnerId == m.RunnerId); nr.LastDistance = db.distances.SingleOrDefault(d => d.Value == last.Distance).Name; nr.LastTime = RaceCalc.formatTime(last.Time); nr.RunnerName = m.runner.firstname + " " + m.runner.secondname; nr.Time = RaceCalc.formatTime(m.Time); vm.Add(nr); } var ds = Convert.ToDouble(distances); ViewBag.NewDistance = db.distances.SingleOrDefault(d => d.Value == ds).Name; return(View(vm)); }
public void CleanupEvents() { Delegate[] delegates = DriversChanged?.GetInvocationList(); if (delegates != null) { foreach (var d in delegates) { DriversChanged -= (EventHandler)d; } } delegates = NextRace?.GetInvocationList(); if (delegates != null) { foreach (var d in delegates) { NextRace -= (EventHandler)d; } } }