Beispiel #1
0
 public static LeagueResults_GetFixture_Result LeagueResult_GetFixture(int FixtureId)
 {
     using (ClubWorldDbContext db = new ClubWorldDbContext())
     {
         return(db.LeagueResults_GetFixture(FixtureId).SingleOrDefault());
     }
 }
Beispiel #2
0
 public static void LeagueResult_AddResultPlayers(int ResultRef, int RegistrationRef)
 {
     using (ClubWorldDbContext db = new ClubWorldDbContext())
     {
         db.LeagueResults_AddResultPlayers(ResultRef, RegistrationRef);
     }
 }
Beispiel #3
0
 public static List <LeagueResult_TeamsForFixture_Result> LeagueResult_GetTeamsForFixture(int FixtureId)
 {
     using (ClubWorldDbContext db = new ClubWorldDbContext())
     {
         return(db.LeagueResult_TeamsForFixture(FixtureId).ToList());
     }
 }
Beispiel #4
0
        public static int LeagueResult_AddResult(int FixtureRef, int HomeShots, int AwayShots)
        {
            ObjectParameter resultRef = new ObjectParameter("ResultId", typeof(Int32));

            using (ClubWorldDbContext db = new ClubWorldDbContext())
            {
                db.LeagueResults_AddResult(FixtureRef, HomeShots, AwayShots, resultRef);
                return((int)resultRef.Value);
            }
        }
Beispiel #5
0
 public static List <LeagueFixtureType> LeagueResult_GetFixtureTypes()
 {
     using (ClubWorldDbContext db = new ClubWorldDbContext())
     {
         return((
                    from ft in db.League_FixtureType
                    select new LeagueFixtureType
         {
             FixturteTypeId = ft.FixtureTypeId,
             Description = ft.Name,
             RinksRequired = ft.RinksRequired
         }).ToList());
     }
 }
Beispiel #6
0
        public static void LeagueResult_InsertResultRecords(List <ResultRecord> resultList)
        {
            using (ClubWorldDbContext db = new ClubWorldDbContext())
            {
                DbContextTransaction tran = db.Database.BeginTransaction();

                foreach (ResultRecord res in resultList)
                {
                    League_Result resEntity = new League_Result
                    {
                        FixtureRef = res.FixtureRef,
                        ResultType = res.FixtureType,
                        HomeShots  = res.HomeShots,
                        AwayShots  = res.AwayShots
                    };
                    db.League_Result.Add(resEntity);

                    db.SaveChanges();

                    int resID = resEntity.ResultID;

                    League_Fixtures fixEntity = db.League_Fixtures.SingleOrDefault(lf => lf.FixtureId == res.FixtureRef);
                    fixEntity.FixtureTypeRef = res.FixtureType;

                    foreach (Player p in res.HomeRink)
                    {
                        League_ResultPlayers lrp = new League_ResultPlayers
                        {
                            ResultRef       = resEntity.ResultID,
                            RegistrationRef = p.RegistrationId
                        };

                        db.League_ResultPlayers.Add(lrp);
                    }
                }
                db.SaveChanges();

                tran.Commit();
            }
        }
Beispiel #7
0
        public List <Fixture> LeagueResults_FixturesForLeague(int LeagueId, int NoOfRecs = 10)
        {
            Repository <LeagueResults_FixturesForLeague_Result> repo = new Repository <LeagueResults_FixturesForLeague_Result>(db);

            using (ClubWorldDbContext db = new ClubWorldDbContext())
            {
                return
                    ((from fix in repo.(LeagueId)
                      where fix.Completed == 0
                      select new Fixture
                {
                    FixtureRef = fix.FixtureId,
                    DiaryRef = fix.DiaryId,
                    BookedDate = fix.BookedDate.ToString(@"ddd dd MMM yyyy"),
                    HomeTeamName = fix.HomeName,
                    HomeTeamRef = fix.HomeTeamRef,
                    AwayTeamName = fix.AwayName,
                    AwayTeamRef = fix.AwayTeamRef
                }).Take(NoOfRecs).ToList());

                //return db.LeagueResults_FixturesForLeague(LeagueId).Take(NoOfRecs).ToList();
                return
                    ((from fix in db.LeagueResults_FixturesForLeague(LeagueId)
                      where fix.Completed == 0
                      select new Fixture
                {
                    FixtureRef = fix.FixtureId,
                    DiaryRef = fix.DiaryId,
                    BookedDate = fix.BookedDate.ToString(@"ddd dd MMM yyyy"),
                    HomeTeamName = fix.HomeName,
                    HomeTeamRef = fix.HomeTeamRef,
                    AwayTeamName = fix.AwayName,
                    AwayTeamRef = fix.AwayTeamRef
                }).Take(NoOfRecs).ToList());
            }
        }
Beispiel #8
0
        public void AssignDates(DateTime StartDate, List <String> SessionsRequested, List <string> DaysRequested, Boolean AllSessionsForDay)
        {
            IEnumerator <GetFreeRinks_Result> rinks = null;
            int?rinksRequired = _Repository.GetRinksPerGame(_fixtures.LeagueId);

            int p1 = ListToFlag(SessionsRequested);
            int p2 = ListToFlag(DaysRequested);
            int MaxRinksAvailable;
            List <GetFreeRinks_Result> r1;

            if (SessionsRequested.Count() > 1 & !AllSessionsForDay)
            {
                p1 = (int)Math.Pow(2, double.Parse(SessionsRequested[0]) - 1);
                r1 = _db.GetFreeRinks(StartDate, p1, p2, 0, rinksRequired).ToList();

                p1 = (int)Math.Pow(2, double.Parse(SessionsRequested[1]) - 1);
                var r2 = _db.GetFreeRinks(StartDate, p1, p2, 1, rinksRequired).ToList();
                rinks = r1.Union(r2).OrderBy(s => s.AvDate).GetEnumerator();

                MaxRinksAvailable = r1.Sum(sr => sr.SpareRinks ?? default(int)) + r2.Sum(sr => sr.SpareRinks ?? default(int));
            }
            else
            {
                r1 = _db.GetFreeRinks(StartDate, p1, p2, 2, rinksRequired).ToList();
                MaxRinksAvailable = r1.Sum(sr => sr.SpareRinks ?? default(int));
                rinks             = r1.GetEnumerator();
            }



            if (MaxRinksAvailable < _fixtures.TotalGames())
            {
                return;
            }

            rinks.MoveNext();
            int rinksLeft     = rinks.Current.SpareRinks ?? default(int);
            int rinksLeftFlag = rinks.Current.RinkFlag ?? default(int);

            foreach (Games round in _fixtures.Series)
            {
                foreach (Game game in round.Round)
                {
                    if (game.HomeTeam.Id * game.AwayTeam.Id > 0)    //  Zero equates to a bye
                    {
                        if (rinksLeft >= rinksRequired)
                        {
                            game.AssignedDate = rinks.Current.AvDate ?? DateTime.Now;

                            int rinksUsedFlag = 0;
                            int counter       = 0;

                            foreach (int r in FindFreeRinks(rinksLeftFlag))
                            {
                                rinksUsedFlag |= r;
                                rinksLeftFlag |= r;
                                counter       += 1;
                                if (counter == rinksRequired)
                                {
                                    rinksLeft -= counter;
                                    break;
                                }
                            }

                            using (ClubWorldDbContext saveContext = new ClubWorldDbContext())
                            {
                                saveContext.AddNewFixture(_fixtures.LeagueName, game.AssignedDate, 1, rinksUsedFlag, rinks.Current.SessionRef, _fixtures.LeagueId, game.HomeTeam.Id, game.AwayTeam.Id);
                            }

                            rinksUsedFlag = 0;
                        }
                        else
                        {
                            rinks.MoveNext();
                            rinksLeft     = rinks.Current.SpareRinks ?? default(int);
                            rinksLeftFlag = rinks.Current.RinkFlag ?? default(int);
                        }
                    }
                }
                rinks.MoveNext();
                rinksLeft     = rinks.Current.SpareRinks ?? default(int);
                rinksLeftFlag = rinks.Current.RinkFlag ?? default(int);
            }
        }
Beispiel #9
0
 public Fixtures(ClubWorldDbContext context)
     : base(context)
 {
 }