示例#1
0
 public TimeStartnumberModel(TimerModel timer)
 {
     this.Timer = timer;
     var intermediates = new List<RaceIntermediateModel>();
     CheckpointIntermediates = new Dictionary<int, List<RaceIntermediateModel>>();
     CheckpointIntermediates.Add(timer.GetFirstCheckpointId(), intermediates);
     using (var context = new Entities())
     {
         foreach (var checkpoint in CheckpointModel.GetCheckpoints(timer.RaceID.Value))
         {
             var raceintermediates = context.RaceIntermediates.Where(interm => interm.CheckpointID == checkpoint.Id).Select(interm => new RaceIntermediateModel()
             {
                 AthleteId = interm.AthleteId.HasValue ? interm.AthleteId.Value : 0,
                 CheckpointID = interm.CheckpointID,
                 CheckpointOrderID = interm.CheckpointOrderID,
                 RuntimeId = interm.RuntimeId
             }).ToList();
             if (!CheckpointIntermediates.ContainsKey(checkpoint.Id))
                 CheckpointIntermediates.Add(checkpoint.Id, raceintermediates);
             else
                 CheckpointIntermediates[checkpoint.Id] = raceintermediates;
         }
     }
     this.Intermediates = intermediates;
 }
示例#2
0
        public void It_Should_Be_Possible_To_Connect_An_Athlete_To_A_Startnumber()
        {
            Given("we have an athlete and a startnumber registrert", () =>
            {
                athlete.ConnectToRace(race.RaceId);
                timer = CreateNewTimerModelWithCheckpoints(race);
                checkpointOrder = new CheckpointOrderModel();
                checkpointOrder.AddCheckpointOrderDB(timer.CurrentCheckpointId, 1);
                timer.Start();
                timer.AddRuntime(400, timer.GetFirstCheckpointId());
                intermediate = new RaceIntermediateModel(timer.CurrentCheckpointId, checkpointOrder.ID, timer.CheckpointRuntimes[timer.CurrentCheckpointId].First().Key);
                intermediate.Save();
            });

            When("we want to connect athletes to startnumbers", () =>
            {
                RaceIntermediateModel.MergeAthletes(race.RaceId);
            });

            Then("athletes should be connected to raceintermediate", () =>
            {
                RaceIntermediateModel.GetRaceintermediatesForRace(race.RaceId).First().AthleteId.ShouldNotBeNull();

            });
        }
 public void TestSetup()
 {
     timeMerger = new TimeMergerModel();
     timer = new TimerModel();
     checkpoint1 = new CheckpointModel("Checkpoint1", timer, 1);
     checkpoint2 = new CheckpointModel("Checkpoint2", timer, 2);
     timer.CurrentCheckpointId = timer.GetFirstCheckpointId();
     timer.CheckpointRuntimes.Add(timer.CurrentCheckpointId, new Dictionary<int, int>());
     checkpointOrderModel = new CheckpointOrderModel();
 }
示例#4
0
 public void TestSetup()
 {
     eventModel = new EventModel("TestEvent", DateTime.Today);
     eventModel.Save();
     race = new RaceModel("TestRace", DateTime.Today);
     race.EventId = eventModel.EventId;
     race.Save();
     timer = new TimerModel();
     timer.SaveToDb();
 }
示例#5
0
 public static TimerModel GetTimerById(int id)
 {
     using (var ctx = new Entities())
     {
         var timer = ctx.Timers.Single(tmr => tmr.TimerID == id);
         var timerDal = new TimerModel()
         {
             Id = timer.TimerID,
             StartTime = timer.StartTime,
             EndTime = timer.EndTime
         };
         return timerDal;
     }
 }
示例#6
0
        public ActionResult Index()
        {
            var timer = new TimerModel();

            if (Session["timer"] == null)
            {
                Session["timer"] = timer;
            }
            else
            {
                timer = (TimerModel)Session["timer"];
            }
            return View("Index", timer);
        }
示例#7
0
        public static TimerModel Create()
        {
            TimerModel timerModel = new TimerModel();

            using (var ctx = new Entities())
            {
                Timer timer = new Timer();
                ctx.Timers.AddObject(timer);
                ctx.SaveChanges();
                timerModel.Id = ctx.Timers.OrderByDescending(tmr => tmr.TimerID).First().TimerID;
            }

            return timerModel;
        }
示例#8
0
 /// <summary>
 /// Creates the new timer model with checkpoints.
 /// </summary>
 /// <returns></returns>
 private void Setup()
 {
     eventModel = new EventModel("Testevent", DateTime.Today);
     eventModel.Save();
     race = new RaceModel("Testrace", DateTime.Today);
     race.EventId = eventModel.EventId;
     race.Save();
     timer = new TimerModel();
     timer.RaceID = race.RaceId;
     checkpoint = new CheckpointModel("Checkpoint1", timer, race, 1);
     checkpoint.SaveToDb();
     checkpointorder = new CheckpointOrderModel();
     checkpointorder.AddCheckpointOrderDB(checkpoint.Id, 12);
     checkpointorder.StartingNumber = 12;
     timer.CurrentCheckpointId = timer.GetFirstCheckpointId();
     timer.CheckpointRuntimes.Add(timer.CurrentCheckpointId, new Dictionary<int, int>());
     timer.SaveToDb();
     timestart = new TimeStartnumberModel(timer);
     timestart.CheckpointOrder = checkpointorder;
     //timestart.AddStartnumber(checkpoint.Id, checkpointorder.StartingNumber, 500);
 }
示例#9
0
 private string SaveToSessionAndReturnRuntimes(TimerModel timer)
 {
     var runtimeDic = timer.CheckpointRuntimes[timer.CurrentCheckpointId].ToListboxvalues(sorting: ExtensionMethods.ListboxSorting.Descending, toTimer: true);
     Session["timer"] = timer;
     return runtimeDic;
 }
示例#10
0
 public ActionResult Speaker(int id)
 {
     ViewBag.RaceId = id;
     var race = RaceModel.GetById(id);
     ViewBag.RaceName = race.Name;
     TimerModel timer = null;
     if (race.GetTimerId().HasValue)
         timer = TimerModel.GetTimerById(race.GetTimerId().Value);
     else
     {
         timer = new TimerModel();
         timer.RaceID = id;
     }
     timer.SaveToDb();
     ViewBag.RaceId = id;
     Session["timer"] = timer;
     var raceintermediates = RaceIntermediateModel.GetRaceintermediatesForRace(id).
         Select(raceintermediate => new ResultsViewModel()
         {
             Checkpointname = raceintermediate.CheckpointModel.Name,
             Clubname = raceintermediate.AthleteId.HasValue ? raceintermediate.AthleteModel.Club.Name : " - ",
             Fullname = raceintermediate.AthleteId.HasValue ? raceintermediate.AthleteModel.FullNameClass : " - ",
             Startnumber = raceintermediate.AthleteId.HasValue ? (raceintermediate.AthleteModel.StartNumber.HasValue ? raceintermediate.AthleteModel.StartNumber.Value : 0) : raceintermediate.CheckpointorderModel.StartingNumber,
             Time = raceintermediate.RuntimeModel.RuntimeToTime
         });
     return View("Speaker", raceintermediates);
 }
示例#11
0
 public ActionResult Index(int id)
 {
     var race = RaceModel.GetById(id);
     ViewBag.RaceName = race.Name;
     TimerModel timer;
     if (race.GetTimerId().HasValue)
         timer = TimerModel.GetTimerById(race.GetTimerId().Value);
     else
     {
         timer = new TimerModel();
         timer.RaceID = id;
     }
     timer.SaveToDb();
     ViewBag.Checkpoints = CheckpointModel.GetCheckpoints(id);
     ViewBag.RaceId = id;
     Session["timer"] = timer;
     return View("Index", timer);
 }
示例#12
0
        public void Two_TimerModels_With_Same_Properties_Should_Equal_Each_Other()
        {
            ITimeU.Models.Timer timer1 = null;
            ITimeU.Models.Timer timer2 = null;

            TimerModel timerModel1 = null;
            TimerModel timerModel2 = null;

            Given("we have some common properties of two timers", () =>
            {
                // Common properties...
                int timerId = 5;
                DateTime startTime = DateTime.Now;
                DateTime endTime = startTime.Add(new TimeSpan(5, 3, 2)); // 5 hours, 3 minutes, 2 seconds

                timer1 = createTimer(timerId, startTime, endTime);
                timer2 = createTimer(timerId, startTime, endTime);
            });

            When("we create two timers with the same properties", () =>
            {
                timerModel1 = new TimerModel(timer1);
                timerModel2 = new TimerModel(timer2);
            });

            Then("the two timers should equal each other (though not same instance)", () =>
            {
                timerModel1.ShouldNotBeSameAs(timerModel2);
                timerModel1.ShouldBe(timerModel2);
            });
        }
示例#13
0
        public void Timer_Id_Should_Be_Zero_Before_Timer_Has_Saved_Data()
        {
            TimerModel newTimer = null;
            When("we create a new timer", () =>
            {
                newTimer = new TimerModel();
            });

            Then("its ID should be zero", () => newTimer.Id.ShouldBe(0));
        }
示例#14
0
 public void TestSetup()
 {
     timer = new TimerModel();
     eventModel = new EventModel("TestEvent", DateTime.Today);
     eventModel.Save();
     race = new RaceModel("SomeRace", new DateTime(2007, 10, 3));
     race.EventId = eventModel.EventId;
     race.Save();
     checkpoint = new CheckpointModel("Checkpoint1", timer, race, 1);
     checkpoint2 = new CheckpointModel("Checkpoint2", timer, race, 2);
     timer.CurrentCheckpointId = timer.GetFirstCheckpointId();
     timer.CheckpointRuntimes.Add(timer.CurrentCheckpointId, new Dictionary<int, int>());
 }
示例#15
0
        public void Setting_A_Timers_Start_Time_Should_Be_Rounded()
        {
            ITimeU.Models.Timer t = null;
            TimerModel timerDb = null;
            Given("we have a timer database entry with a start time set to 42.972 seconds", () =>
            {
                t = new ITimeU.Models.Timer();
                t.StartTime = new DateTime(2010, 8, 5, 23, 45, 42, 972);
            });

            When("we create a timer model based on the timer entry", () =>
            {
                timerDb = new TimerModel(t);
            });

            Then("the time should be rounded to 43 seconds and 0 milliseconds", () =>
            {
                timerDb.StartTime.Value.Second.ShouldBe(43);
                timerDb.StartTime.Value.Millisecond.ShouldBe(0);
            });
        }
示例#16
0
 public void TestSetup()
 {
     timeMerger = new TimeMergerModel();
     timer = new TimerModel();
     eventModel = new EventModel("Testevent", DateTime.Today);
     eventModel.Save();
     race = new RaceModel("SomeRace", new DateTime(2007, 10, 3));
     race.EventId = eventModel.EventId;
     race.Save();
     checkpoint1 = new CheckpointModel("Checkpoint1", timer, race, 1);
     checkpoint2 = new CheckpointModel("Checkpoint2", timer, race, 2);
     timer.RaceID = race.RaceId;
     timer.CurrentCheckpointId = timer.GetFirstCheckpointId();
     timer.CheckpointRuntimes.Add(timer.CurrentCheckpointId, new Dictionary<int, int>());
     checkpointOrderModel = new CheckpointOrderModel();
     timestartnumberModel = new TimeStartnumberModel(timer);
     timestartnumberModel.ChangeCheckpoint(timer.GetFirstCheckpointId());
     timestartnumberModel.CheckpointOrder = checkpointOrderModel;
 }
示例#17
0
        public void We_Should_Be_Able_To_Insert_And_Fetch_A_Checkpoint_With_A_Race_To_Database()
        {
            CheckpointModel checkpointDb = null;
            TimerModel timer = new TimerModel();
            timer.SaveToDb();

            Given("we have a checkpoint in the database", () =>
            {
            });

            When("we fetch the same checkpoint from database", () =>
            {
                checkpointDb = CheckpointModel.getById(checkpoint.Id);
            });

            Then("the checkpoints should be the same", () =>
            {
                checkpointDb.Name.ShouldBe(checkpoint.Name);
                checkpointDb.Race.RaceId.ShouldBe(checkpoint.Race.RaceId);
            });
        }
示例#18
0
 /// <summary>
 /// Creates the new timer model with checkpoints.
 /// </summary>
 /// <returns></returns>
 private TimerModel CreateNewTimerModelWithCheckpoints(RaceModel race)
 {
     timer = new TimerModel();
     timer.RaceID = race.RaceId;
     checkpoint = new CheckpointModel("Checkpoint1", timer, race, 1);
     timer.CurrentCheckpointId = timer.GetFirstCheckpointId();
     timer.CheckpointRuntimes.Add(timer.CurrentCheckpointId, new Dictionary<int, int>());
     return timer;
 }
示例#19
0
        public ActionResult Index(int raceId)
        {
            var race = RaceModel.GetById(raceId);

            TimerModel timer;
            if (race.GetTimerId().HasValue)
                timer = TimerModel.GetTimerById(race.GetTimerId().Value);
            else
            {
                timer = new TimerModel();
                timer.RaceID = raceId;
            }
            timer.SaveToDb();

            TimeStartnumberModel timeStartnumberModel;
            timeStartnumberModel = new TimeStartnumberModel(timer);
            var checkpointOrder = new CheckpointOrderModel();

            ViewBag.Checkpoints = CheckpointModel.GetCheckpoints(raceId);
            ViewBag.RaceId = raceId;
            ViewBag.RaceName = race.Name;
            timeStartnumberModel.ChangeCheckpoint(timer.GetFirstCheckpointId());
            timeStartnumberModel.CheckpointOrder = checkpointOrder;
            Session["TimeStartnumber"] = timeStartnumberModel;
            return View("Index", timeStartnumberModel);
        }