public int DeleteRace(Race race) { var drivers = race.Drivers.ToList(); foreach (var driver in drivers) { if (driver.Racer.RawBestTime == driver.RawRaceTime) { // This is the drivers best race, and we're deleting it :( // Update their best time to their next highest race: int driverId = driver.RacerId; var nextBest = _context.CurrentDrivers.Where(d => d.RacerId == driverId && d.RaceId != race.RaceId).OrderBy(d => d.RawRaceTime).FirstOrDefault(); driver.Racer.RawBestTime = null != nextBest ? nextBest.RawRaceTime : 0; } _context.CurrentDrivers.Remove(driver); } _context.Races.Remove(race); return Save(); }
public ActionResult Edit(Race race) { if (ModelState.IsValid) { _db.Entry(race).State = EntityState.Modified; _db.SaveChanges(); return RedirectToAction("Index"); } return View(race); }
/// <summary> /// Create a new Race object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="startTime">Initial value of the StartTime property.</param> /// <param name="endTime">Initial value of the EndTime property.</param> public static Race CreateRace(global::System.Int32 id, global::System.DateTime startTime, global::System.DateTime endTime) { Race race = new Race(); race.Id = id; race.StartTime = startTime; race.EndTime = endTime; return race; }
/// <summary> /// Deprecated Method for adding a new object to the Races EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToRaces(Race race) { base.AddObject("Races", race); }
public void UpdateRace(Race currentRace) { Clients.All.updateRace(currentRace); }
public void AddRace(Race race) { throw new NotImplementedException(); }
private void loadOrderedDrivers(Race currentRace) { if (null == currentRace) { return; } var drivers = _context.Entry(currentRace); drivers.Collection(e => e.Drivers).Query().OrderBy(d => d.Lane).Include(d => d.Car).Include(d => d.Racer).Load(); }
public CurrentDriver GetWinner(Race race) { if (race.IsComplete) { return race.Drivers.OrderBy(cr => cr.RawRaceTime).First(); } return null; }
public ActionResult Index(Race newRace) { if (ModelState.IsValid) { _db.Races.Add(newRace); _db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.CarId = new SelectList(_db.Cars.OrderBy(c => c.CarId), "CarId", "Name"); ViewBag.RacerId = new SelectList(getFormattedRacers(), "RacerId", "Name"); return View(newRace); }