Inheritance: System.Data.Objects.DataClasses.EntityObject
Exemple #1
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;
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TimerModel"/> class.
 /// </summary>
 /// <param name="timer">The timer.</param>
 public TimerModel(Timer timer)
 {
     Id = timer.TimerID;
     StartTime = timer.StartTime;
     EndTime = timer.EndTime;
     CheckpointRuntimes = new Dictionary<int, Dictionary<int, int>>();
     CheckpointRuntimes.Add(CurrentCheckpointId, new Dictionary<int, int>());
     if (StartTime != null && EndTime == null)
         IsStarted = true;
     if (timer.RaceID.HasValue)
     {
         RaceID = timer.RaceID.Value;
         using (var context = new Entities())
         {
             foreach (var checkpoint in CheckpointModel.GetCheckpoints(timer.RaceID.Value))
             {
                 var runtimes = context.Runtimes.Where(runt => runt.CheckpointID == checkpoint.Id && !runt.IsDeleted).Select(runt => new RuntimeModel()
                 {
                     Id = runt.RuntimeID,
                     CheckPointId = runt.CheckpointID,
                     Runtime = runt.Runtime1,
                     IsMerged = runt.IsMerged
                 }).OrderBy(runt => runt.Runtime).ToList();
                 foreach (var runtime in runtimes)
                 {
                     if (!CheckpointRuntimes.ContainsKey(checkpoint.Id))
                     {
                         CheckpointRuntimes.Add(checkpoint.Id, new Dictionary<int, int>());
                         CheckpointRuntimes[checkpoint.Id].Add(runtime.Id, runtime.Runtime);
                     }
                     else
                         CheckpointRuntimes[checkpoint.Id].Add(runtime.Id, runtime.Runtime);
                 }
             }
         }
     }
 }
Exemple #3
0
        public void A_DateTime_Value_In_Db_Should_Equal_The_Actual_DateTime_Value()
        {
            ITimeU.Models.Timer t = null;
            Entities context = null;

            Given("we have a timer database entry with a start time", () =>
            {
                t = new ITimeU.Models.Timer();
                t.StartTime = new DateTime(2010, 8, 5, 23, 45, 40, 799);
            });

            When("we save the timer to the database", () =>
            {
                context = new Entities();
                context.Timers.AddObject(t);
                context.SaveChanges();
            });

            Then("the start time should be the same in the timer and in the database", () =>
            {
                var tDb = context.Timers.Single(tmr => tmr.TimerID == t.TimerID);
                tDb.StartTime.ShouldBe(t.StartTime);
            });
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Timers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToTimers(Timer timer)
 {
     base.AddObject("Timers", timer);
 }
 /// <summary>
 /// Create a new Timer object.
 /// </summary>
 /// <param name="timerID">Initial value of the TimerID property.</param>
 /// <param name="isDeleted">Initial value of the IsDeleted property.</param>
 public static Timer CreateTimer(global::System.Int32 timerID, global::System.Boolean isDeleted)
 {
     Timer timer = new Timer();
     timer.TimerID = timerID;
     timer.IsDeleted = isDeleted;
     return timer;
 }
Exemple #6
0
        private static ITimeU.Models.Timer createTimer(int timerId, DateTime startTime, DateTime endTime)
        {
            ITimeU.Models.Timer timer = new ITimeU.Models.Timer();

            timer.TimerID = timerId;
            timer.StartTime = startTime;
            timer.EndTime = endTime;

            return timer;
        }
Exemple #7
0
        public void Setting_A_Timers_Start_Time_Should_Be_Rounded_Also_When_Saving_To_Db()
        {
            ITimeU.Models.Timer t = 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 save the timer entry to database and retrieve it back", () =>
            {
                var context = new Entities();
                context.Timers.AddObject(t);
                context.SaveChanges();
            });

            Then("the time should be rounded to 43 seconds and 0 milliseconds", () =>
            {
                TimerModel timerDb = TimerModel.GetTimerById(t.TimerID);

                timerDb.StartTime.Value.Second.ShouldBe(43);
                timerDb.StartTime.Value.Millisecond.ShouldBe(0);
            });
        }
Exemple #8
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);
            });
        }
Exemple #9
0
        /// <summary>
        /// Creates the db entity.
        /// </summary>
        /// <returns></returns>
        private int CreateDbEntity()
        {
            var context = new Entities();

            Timer timer = new Timer();
            context.Timers.AddObject(timer);
            context.SaveChanges();

            dbEntryCreated = true;
            return timer.TimerID;
        }