Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        public ActionResult Edit(Race race)
        {
            if (ModelState.IsValid)
              {
            _db.Entry(race).State = EntityState.Modified;
            _db.SaveChanges();

            return RedirectToAction("Index");
              }

              return View(race);
        }
Exemplo n.º 3
0
 /// <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;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Races EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRaces(Race race)
 {
     base.AddObject("Races", race);
 }
Exemplo n.º 5
0
 public void UpdateRace(Race currentRace)
 {
     Clients.All.updateRace(currentRace);
 }
Exemplo n.º 6
0
 public void AddRace(Race race)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 8
0
        public CurrentDriver GetWinner(Race race)
        {
            if (race.IsComplete)
              {
            return race.Drivers.OrderBy(cr => cr.RawRaceTime).First();
              }

              return null;
        }
Exemplo n.º 9
0
        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);
        }