No Metadata Documentation available.
Наследование: ObjectContext
Пример #1
0
        public void We_Should_Be_Able_To_Update_A_Club()
        {
            ViewResult result = null;
            string newName = "NewClubname";

            Given("we have a club and a controller", () =>
            {
                controller = new ClubController();
            });

            When("we want to update the club", () =>
            {
                club.Name = newName;
                controller.Edit(club);
            });

            Then("the club's name should be updated", () =>
            {
                using (var context = new Entities())
                {
                    var clubDb = context.Clubs.Single(clb => clb.ClubID == club.Id);
                    clubDb.Name.ShouldBe(newName);
                }
            });
        }
Пример #2
0
 /// <summary>
 /// Gets the race athletes for race.
 /// </summary>
 /// <param name="raceid">The raceid.</param>
 /// <returns></returns>
 public static List<RaceAthleteModel> GetAthletesConnectedToRace(int raceid)
 {
     using (var context = new Entities())
     {
         return context.RaceAthletes.
             Where(raceAthlete => raceAthlete.RaceId == raceid).
             Select(raceAthlete => new RaceAthleteModel()
             {
                 RaceId = raceAthlete.RaceId,
                 RaceModel = new RaceModel()
                 {
                     RaceId = raceAthlete.RaceId,
                     Name = raceAthlete.Race.Name,
                     Distance = raceAthlete.Race.Distance.HasValue ? raceAthlete.Race.Distance.Value : 0,
                     StartDate = raceAthlete.Race.StartDate
                 },
                 AthleteId = raceAthlete.AthleteId,
                 AthleteModel = new AthleteModel()
                 {
                     Id = raceAthlete.AthleteId,
                     FirstName = raceAthlete.Athlete.FirstName,
                     LastName = raceAthlete.Athlete.LastName,
                     Birthday = raceAthlete.Athlete.Birthday,
                     StartNumber = raceAthlete.Athlete.Startnumber
                 },
                 Startnumber = raceAthlete.Startnumber
             }
             ).ToList();
     }
 }
 private static bool CheckpointWithStartNumberExists(int checkpointId, int startingNumber, Entities entities)
 {
     return entities.CheckpointOrders.Any(
         chkpnt =>
             (chkpnt.StartingNumber == startingNumber &&
             chkpnt.CheckpointID == checkpointId));
 }
Пример #4
0
 public static List<RaceIntermediate> GetMergedList(int checkpointId)
 {
     using (var context = new Entities())
     {
         return context.RaceIntermediates.Where(intermediates => intermediates.IsDeleted == false && intermediates.CheckpointID == checkpointId).ToList();
     }
 }
Пример #5
0
 public static bool EventNameExists(string eventName)
 {
     using (var context = new Entities())
     {
         return context.Events.Any(evnt => evnt.Name.ToLower() == eventName.ToLower() && !evnt.IsDeleted);
     }
 }
        public void Get_Next_OrderNumber_In_Ascending_Order_After_Inserting_StartNumber()
        {
            CheckpointOrderModel testCheckpointOrder = null;
            int ordernum1 = 0, ordernum2 = 0;
            int checkpointId = 1;
            Entities context = new Entities();
            Given("We have a CheckpointOrder", () =>
            {
                testCheckpointOrder = new CheckpointOrderModel();

            });

            When("We insert start number", () =>
            {
                testCheckpointOrder.AddCheckpointOrderDB(checkpointId, 2);
                ordernum1 = (int)(context.CheckpointOrders.OrderByDescending(ordnum => ordnum.OrderNumber).First().OrderNumber);
            });

            Then("We should have next order number in ascending order in database", () =>
            {
                testCheckpointOrder.AddCheckpointOrderDB(checkpointId, 3);
                ordernum2 = (int)(context.CheckpointOrders.OrderByDescending(ordnum => ordnum.OrderNumber).First().OrderNumber);
                ordernum2.ShouldBe(ordernum1 + 1);
            });
        }
 private static int GetHighestExistingOrderNumberForCheckpoint(int checkpointId, Entities entities)
 {
     return (int) entities.CheckpointOrders.
         Where(chkpntid => chkpntid.CheckpointID == checkpointId).
         OrderByDescending(chkpnt => chkpnt.OrderNumber).
         First().OrderNumber;
 }
Пример #8
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;
 }
Пример #9
0
 public static void Merge(int checkpointId)
 {
     using (var context = new Entities())
     {
         var timestamps = context.Runtimes.Where(runtime => runtime.CheckpointID == checkpointId && !runtime.IsDeleted).OrderBy(runtime => runtime.Runtime1).ToList();
         var startnumbers = context.CheckpointOrders.Where(startnumber => startnumber.CheckpointID == checkpointId && !startnumber.IsDeleted).OrderBy(startnumber => startnumber.OrderNumber).ToList();
         var raceintermediates = context.RaceIntermediates.Where(intermediate => intermediate.CheckpointID == checkpointId).ToList();
         //Removes exicting entries in the database
         foreach (var intermediate in raceintermediates)
         {
             context.DeleteObject(intermediate);
         }
         context.SaveChanges();
         //Creates new entries
         int i = 0;
         foreach (var timestamp in timestamps)
         {
             if (startnumbers.Count < i + 1)
                 break;
             Merge(checkpointId, startnumbers[i].ID, timestamp.RuntimeID);
             i++;
         }
     }
     var checkpoint = CheckpointModel.getById(checkpointId);
     RaceIntermediateModel.MergeAthletes(checkpoint.RaceId.Value);
 }
        private int CreateCheckpointWithStartNumber(int checkpointId, int startingNumber, Entities entities)
        {
            var checkpointOrder = CreateCheckpointOrder(checkpointId, startingNumber, entities);
            SaveCheckpointOrder(checkpointOrder, entities);
            AddToCheckpointOrderDic(checkpointId, entities);

            return checkpointOrder.ID;
        }
        public int AddCheckpointOrderDB(int checkpointId, int startingNumber)
        {
            var entities = new Entities();

            if (CheckpointWithStartNumberExists(checkpointId, startingNumber, entities))
                return 0;
            else
                return CreateCheckpointWithStartNumber(checkpointId, startingNumber, entities);
        }
Пример #12
0
 /// <summary>
 /// Deletes the runtime.
 /// </summary>
 /// <param name="runtimeid">The runtimeid.</param>
 public static void DeleteRuntime(int runtimeid)
 {
     using (var ctx = new Entities())
     {
         var runtimeToDelete = ctx.Runtimes.Where(runt => runt.RuntimeID == runtimeid).Single();
         runtimeToDelete.IsDeleted = true;
         ctx.SaveChanges();
     }
 }
Пример #13
0
 public static RaceModel GetById(int idToGet)
 {
     var entities = new Entities();
     try
     {
         return TryToGetById(idToGet, entities);
     }
     catch (InvalidOperationException)
     {
         throw new ModelNotFoundException(typeof(RaceModel).Name + " with ID " + idToGet + " not found in database.");
     }
 }
Пример #14
0
 /// <summary>
 /// Deletes the raceintermediate.
 /// </summary>
 /// <param name="cpid">The cpid.</param>
 /// <param name="cpOrderid">The cp orderid.</param>
 public static void DeleteRaceintermediate(int cpid, int cpOrderid)
 {
     using (var context = new Entities())
     {
         var raceintermediateToDelete = context.RaceIntermediates.Where(raceintermediate => raceintermediate.CheckpointID == cpid && raceintermediate.CheckpointOrderID == cpOrderid).SingleOrDefault();
         //raceintermediateToDelete.IsDeleted = true;
         RuntimeModel.DeleteRuntime(raceintermediateToDelete.RuntimeId);
         CheckpointOrderModel.DeleteCheckpointOrder(raceintermediateToDelete.CheckpointOrderID);
         context.DeleteObject(raceintermediateToDelete);
         context.SaveChanges();
     }
 }
Пример #15
0
 public static List<EventModel> GetEvents()
 {
     using (var context = new Entities())
     {
         return context.Events.Where(evnt => evnt.IsDeleted == false).Select(evnt => new EventModel()
         {
             EventId = evnt.EventId,
             EventDate = evnt.EventDate,
             Name = evnt.Name
         }).OrderBy(evnt => evnt.Name).ToList();
     }
 }
Пример #16
0
 public static EventModel GetById(int id)
 {
     using (var context = new Entities())
     {
         var eventDb = context.Events.Single(evnt => evnt.EventId == id);
         return new EventModel()
         {
             EventId = eventDb.EventId,
             Name = eventDb.Name,
             EventDate = eventDb.EventDate
         };
     }
 }
Пример #17
0
 public static List<CheckpointOrder> GetCheckpointOrders()
 {
     using (var ctx = new Entities())
     {
         return ctx.CheckpointOrders.Select(chkpnt =>
             new CheckpointOrder()
             {
                 CheckpointID = chkpnt.CheckpointID,
                 StartingNumber = chkpnt.StartingNumber,
                 OrderNumber = chkpnt.OrderNumber
             }).ToList();
     }
 }
Пример #18
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;
        }
Пример #19
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;
     }
 }
        private static CheckpointOrder CreateCheckpointOrder(int checkpointId, int startingNumber, Entities entities)
        {
            var checkpointOrder = new CheckpointOrder();
            checkpointOrder.CheckpointID = checkpointId;
            checkpointOrder.StartingNumber = startingNumber;

            if ((ExistsAnyCheckpointOrdersInDb(entities)) && (CheckpointExistsInDb(checkpointId, entities)))
                checkpointOrder.OrderNumber = GetHighestExistingOrderNumberForCheckpoint(checkpointId, entities) + 1;
            else
                checkpointOrder.OrderNumber = 1;

            checkpointOrder.IsDeleted = false;
            return checkpointOrder;
        }
Пример #21
0
 public static CheckpointOrderModel GetCheckpointOrderById(int id)
 {
     using (var ctx = new Entities())
     {
         var checkpointOrder = ctx.CheckpointOrders.Single(chkpnt => chkpnt.ID == id);
         var checkpointModel = new CheckpointOrderModel()
         {
             ID = checkpointOrder.ID,
             CheckpointID = (int)checkpointOrder.CheckpointID,
             StartingNumber = (int)checkpointOrder.StartingNumber,
             OrderNumber = (int)checkpointOrder.OrderNumber
         };
         return checkpointModel;
     }
 }
Пример #22
0
 public void TestSetup()
 {
     ctxDBTest = new Entities();
     newEvent = new EventModel("TestEvent", DateTime.Today);
     newEvent.Save();
     newRace = new RaceModel("RaceModelTestRace", new DateTime(2009, 2, 3));
     newRace.EventId = newEvent.EventId;
     newRace.Save();
     raceDB = new Race();
     raceDB.EventId = newEvent.EventId;
     raceDB.Name = "TestingRaceModel";
     raceDB.Distance = 200;
     raceDB.StartDate = DateTime.Parse("10/03/2020");
     ctxDBTest.Races.AddObject(raceDB);
     ctxDBTest.SaveChanges();
 }
Пример #23
0
        public static CheckpointOrderModel Create(int checkpointId, int startingNumber, int orderNumber)
        {
            CheckpointOrderModel checkpointOrderModel = new CheckpointOrderModel();

            using (var ctx = new Entities())
            {
                CheckpointOrder checkpointOrder = new CheckpointOrder();
                checkpointOrder.CheckpointID = checkpointId;
                checkpointOrder.StartingNumber = startingNumber;
                checkpointOrder.StartingNumber = (ctx.CheckpointOrders.OrderByDescending(chkpnt => chkpnt.CheckpointID).First().CheckpointID) + 1;
                ctx.CheckpointOrders.AddObject(checkpointOrder);
                ctx.SaveChanges();
                checkpointOrder.ID = (int)ctx.CheckpointOrders.OrderByDescending(chkpnt => chkpnt.CheckpointID).First().CheckpointID;
            }

            return checkpointOrderModel;
        }
Пример #24
0
        public ActionResult Edit(int ID, string value)
        {
            using (var ctx = new Entities())
            {
                CheckpointOrderModel model = (CheckpointOrderModel)Session["checkpoint"];

                int tmpValue = 0;
                if (!int.TryParse(value, out tmpValue))
                {
                    return null;
                }
                tmpValue = int.Parse(value);
                CheckpointOrder origCheckpointOrder = CheckpointOrderModel.GetCheckpointOrderById(ID);
                TimeMergerModel.Merge(origCheckpointOrder.CheckpointID.Value);
                return View("Index", model);
            }
        }
Пример #25
0
        public void Get_Next_OrderNumber_In_Ascending_Order_After_Inserting_StartNumber()
        {
            CheckpointOrderModel testCheckpointOrder = null;
            int ordernum1 = 0, ordernum2 = 0;
            int checkpointId = 1;
            int startnum1 = 4, startnum2 = 5;
            Entities context = new Entities();
            Given("We have a CheckpointOrder", () =>
            {
                testCheckpointOrder = new CheckpointOrderModel();
            });

            When("We insert start number", () =>
            {
                using (var ctxTest = new Entities())
                {
                    if (ctxTest.CheckpointOrders.Any(chkpnt => (chkpnt.StartingNumber == startnum1 && chkpnt.CheckpointID == checkpointId)))
                    {
                        var checkpointOrderToDelete = ctxTest.CheckpointOrders.Where(checkpointOrder => (checkpointOrder.StartingNumber == startnum1 && checkpointOrder.CheckpointID == checkpointId)).Single();
                        ctxTest.CheckpointOrders.DeleteObject(checkpointOrderToDelete);
                        ctxTest.SaveChanges();
                    }
                }
                testCheckpointOrder.AddCheckpointOrderDB(checkpointId, startnum1);
                ordernum1 = (int)(context.CheckpointOrders.Where(chkpnt => chkpnt.CheckpointID == checkpointId).OrderByDescending(ordnum => ordnum.OrderNumber).First().OrderNumber);
            });

            Then("We should have next order number in ascending order in database", () =>
            {
                using (var ctxTest = new Entities())
                {
                    if (ctxTest.CheckpointOrders.Any(chkpnt => (chkpnt.StartingNumber == startnum2 && chkpnt.CheckpointID == checkpointId)))
                    {
                        var checkpointOrderToDelete = ctxTest.CheckpointOrders.Where(checkpointOrder => (checkpointOrder.StartingNumber == startnum2 && checkpointOrder.CheckpointID == checkpointId)).Single();
                        ctxTest.CheckpointOrders.DeleteObject(checkpointOrderToDelete);
                        ctxTest.SaveChanges();
                    }
                }
                testCheckpointOrder.AddCheckpointOrderDB(checkpointId, startnum2);
                ordernum2 = (int)(context.CheckpointOrders.Where(chkpnt => chkpnt.CheckpointID == checkpointId).OrderByDescending(ordnum => ordnum.OrderNumber).First().OrderNumber);
                ordernum2.ShouldBe(ordernum1 + 1);
            });
        }
Пример #26
0
 public static bool Delete(this List<RaceIntermediate> intermediates)
 {
     try
     {
         using (var context = new Entities())
         {
             foreach (var intermediate in intermediates)
             {
                 context.DeleteObject(intermediate);
             }
             context.SaveChanges();
         }
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
Пример #27
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);
                 }
             }
         }
     }
 }
Пример #28
0
        public void Save()
        {
            using (var ctx = new Entities())
            {
                Timer timer = ctx.Timers.Single(tmr => tmr.TimerID == Id);

                timer.StartTime = this.StartTime;
                if (this.EndTime.HasValue)
                    timer.EndTime = this.EndTime;

                ctx.SaveChanges();
            }
        }
Пример #29
0
 private void updateDbEntity(Entities context)
 {
     Athlete athlete = context.Athletes.Single(enitity => enitity.ID == Id);
     updateProperties(athlete);
     context.SaveChanges();
 }
Пример #30
0
 private CheckpointOrder GetCheckpointOrder(int id)
 {
     Entities ent = new Entities();
     var coQuery = from c in ent.CheckpointOrders
                   where c.CheckpointID == id
                   select c;
     CheckpointOrder co = coQuery.FirstOrDefault();
     return co;
 }