Exemplo n.º 1
0
        public GamesCycle UpdateBasketBallWaterPoloScore(GamesCycle gc)
        {
            var lastQuarter = gc.GameSets.OrderByDescending(x => x.GameSetId).FirstOrDefault();

            if (lastQuarter != null)
            {
                if (lastQuarter.HomeTeamScore > lastQuarter.GuestTeamScore)
                {
                    gc.HomeTeamScore  = 1;
                    gc.GuestTeamScore = 0;
                }
                else if (lastQuarter.HomeTeamScore < lastQuarter.GuestTeamScore)
                {
                    gc.GuestTeamScore = 1;
                    gc.HomeTeamScore  = 0;
                }
            }
            else
            {
                gc.HomeTeamScore  = 0;
                gc.GuestTeamScore = 0;
            }

            Update(gc);
            return(gc);
        }
Exemplo n.º 2
0
 public GamesInLeague(GamesCycle model)
 {
     CycleId            = model.CycleId;
     StageId            = model.StageId;
     CycleNum           = model.CycleNum;
     StartDate          = model.StartDate;
     AuditoriumId       = model.AuditoriumId;
     GuestTeamId        = model.GuestTeamId;
     GuestTeamScore     = model.GuestTeamScore;
     HomeTeamId         = model.HomeTeamId;
     HomeTeamScore      = model.HomeTeamScore;
     RefereeId          = model.RefereeId;
     GroupeId           = model.GroupeId;
     GameStatus         = model.GameStatus;
     TechnicalWinnnerId = model.TechnicalWinnnerId;
     MaxPlayoffPos      = model.MaxPlayoffPos;
     MinPlayoffPos      = model.MinPlayoffPos;
     BracketId          = model.BracketId;
     Auditorium         = model.Auditorium;
     Group          = model.Group;
     GuestTeam      = model.GuestTeam;
     HomeTeam       = model.HomeTeam;
     Stage          = model.Stage;
     User           = model.User;
     GameSets       = model.GameSets;
     PlayoffBracket = model.PlayoffBracket;
     NotesGames     = model.NotesGames;
     WallThreads    = model.WallThreads;
     Users          = model.Users;
     IsPublished    = model.IsPublished;
 }
Exemplo n.º 3
0
        public static void UpdateGameSet(int gameSetId, CreateGameSetViewModel viewModel)
        {
            viewModel.GameSetId = gameSetId;

            GameSet gameSet = _gamesRepo.GetGameSetById(gameSetId);

            if (gameSet == null)
            {
                throw new NotFoundEntityException("Game set with this Id doesn't exist");
            }

            GamesCycle gamesCycle = _gamesRepo.GetGameCycleById(viewModel.GameCycleId);

            if (gamesCycle == null)
            {
                throw new NotFoundEntityException("Game cycle with this Id doesn't exist");
            }
            if (!gamesCycle.IsPublished)
            {
                throw new NotFoundEntityException("Game cycle with this Id doesn't published");
            }

            gameSet.InjectFrom(viewModel);
            _gamesRepo.UpdateGameSet(gameSet);
        }
Exemplo n.º 4
0
        public ActionResult Game(GamesCycle gc)
        {
            GamesCycle editGc = gamesRepo.GetGameCycleById(gc.CycleId);

            var leagueId = editGc.Stage.LeagueId;
            var unionId  = editGc.Stage.League.UnionId;
            var seasonId = editGc.Stage.League.SeasonId;
            var uRepo    = new UsersRepo();

            if (unionId != null)
            {
                ViewBag.Referees = uRepo.GetUnionAndLeageReferees(unionId.Value, leagueId);

                var aRepo = new AuditoriumsRepo();
                if (seasonId.HasValue)
                {
                    //if season id has value get all arena's by season id
                    ViewBag.Auditoriums = aRepo.GetByUnionAndSeason(unionId.Value, seasonId.Value);
                }
                else
                {
                    ViewBag.Auditoriums = aRepo.GetAll(unionId.Value);
                }
            }
            return(PartialView("_Game", editGc));
        }
Exemplo n.º 5
0
 public GamesCycle EndGame(GamesCycle gc)
 {
     gc.GameStatus = GameStatus.Ended;
     UpdateGameScore(gc);
     bracketsRepo.GameEndedEvent(gc);
     return(gc);
 }
Exemplo n.º 6
0
        public void BasketBallTechnicalWin(int gameCycleId, int teamId)
        {
            GamesCycle gc = GetGameCycleById(gameCycleId);

            db.GameSets.RemoveRange(gc.GameSets);
            db.SaveChanges();

            GameSet set = null;

            if (teamId == gc.HomeTeamId)
            {
                set = new GameSet
                {
                    HomeTeamScore  = 20,
                    GuestTeamScore = 0,
                    GameCycleId    = gameCycleId
                };
            }
            else
            {
                set = new GameSet
                {
                    HomeTeamScore  = 0,
                    GuestTeamScore = 20,
                    GameCycleId    = gameCycleId
                };
            }
            AddGameSet(set);
            gc.TechnicalWinnnerId = teamId;
            EndGame(gc);
        }
Exemplo n.º 7
0
        private void UpdateWaterPoloScore(GamesCycle gc)
        {
            if (gc.GameSets.Count > 1)
            {
                var lastSet = gc.GameSets.OrderBy(c => c.SetNumber).LastOrDefault();
                if (lastSet != null)
                {
                    DeleteSet(lastSet);
                }
            }


            int hScore = 0;
            int gScore = 0;

            foreach (var set in gc.GameSets)
            {
                if (set.HomeTeamScore > set.GuestTeamScore)
                {
                    hScore++;
                    set.GuestTeamScore = 0;
                    set.HomeTeamScore  = 5;
                }
                else if (set.HomeTeamScore < set.GuestTeamScore)
                {
                    gScore++;
                    set.GuestTeamScore = 5;
                    set.HomeTeamScore  = 0;
                }
            }
            gc.HomeTeamScore  = hScore;
            gc.GuestTeamScore = gScore;

            Update(gc);
        }
Exemplo n.º 8
0
        public PartialViewResult DeleteLastGameSet(int id)
        {
            GamesCycle gc      = gamesRepo.GetGameCycleById(id);
            var        lastSet = gc.GameSets.OrderBy(c => c.SetNumber).LastOrDefault();

            gamesRepo.DeleteSet(lastSet);
            return(GameSetList(id));
        }
Exemplo n.º 9
0
        public GamesCycle StartGame(int id)
        {
            GamesCycle gc = GetGameCycleById(id);

            gc.GameStatus = GameStatus.Started;
            Update(gc);
            return(gc);
        }
Exemplo n.º 10
0
        public void AddGameSet(GameSet set)
        {
            GamesCycle gc            = GetGameCycleById(set.GameCycleId);
            var        lastSetNumebr = gc.GameSets.OrderBy(c => c.SetNumber).Select(c => c.SetNumber).LastOrDefault();

            set.SetNumber = ++lastSetNumebr;
            db.GameSets.Add(set);
            db.SaveChanges();
        }
Exemplo n.º 11
0
 public void RemoveCycle(GamesCycle item)
 {
     db.GameSets.RemoveRange(item.GameSets);
     foreach (var user in item.Users)
     {
         user.UsersGamesCycles = null;
     }
     db.GamesCycles.Remove(item);
     item.Users = null;
 }
Exemplo n.º 12
0
        public static GameViewModel GetLastGame(IEnumerable <GamesCycle> games, int?seasonId = null)
        {
            GamesCycle gameCycle = games.Where(g => g.GameStatus == GameStatus.Ended && g.IsPublished).OrderBy(g => g.StartDate).LastOrDefault();

            if (gameCycle == null)
            {
                return(null);
            }
            GameViewModel vm = ParseGameCycle(gameCycle, seasonId);

            return(vm);
        }
Exemplo n.º 13
0
        public ActionResult AddNew(GameCycleFormFull frm)
        {
            var gc = new GamesCycle();

            UpdateModel(gc);

            var serv = new SchedulingService();

            serv.AddGame(gc);

            return(RedirectToAction("List", new { id = frm.LeagueId, desOrder = Session["desOrder"] }));
        }
Exemplo n.º 14
0
        private void UpdateIfDifferentObject(ExcelGameDto dto, GamesCycle ctxModel)
        {
            #region If/Else
            if (ctxModel.StartDate != dto.Date)
            {
                ctxModel.StartDate = dto.Date;
            }

            else if (ctxModel.Auditorium != null && ctxModel.Auditorium.Name != dto.Auditorium)
            {
                ctxModel.StartDate = dto.Date;
            }

            else if (ctxModel.Group != null && ctxModel.Group.Name != dto.Groupe)
            {
                ctxModel.StartDate = dto.Date;
            }

            else if (ctxModel.GuestTeam != null && ctxModel.GuestTeam.Title != dto.GuestTeam)
            {
                ctxModel.StartDate = dto.Date;
            }

            else if (ctxModel.GuestTeamScore != dto.GuestTeamScore)
            {
                ctxModel.StartDate = dto.Date;
            }
            else if (ctxModel.HomeTeamScore != dto.HomeTeamScore)
            {
                ctxModel.StartDate = dto.Date;
            }
            else if (ctxModel.User != null && ctxModel.User.FullName != dto.Referee)
            {
                ctxModel.StartDate = dto.Date;
            }
            else if (ctxModel.HomeTeam != null && ctxModel.HomeTeam.Title != dto.HomeTeam)
            {
                ctxModel.StartDate = dto.Date;
            }
            else if (ctxModel.GameSets.Any())
            {
                var sets = ctxModel.GameSets.ToArray();

                var set1 = sets.Length > 0 && sets[0].HomeTeamScore > 0 && sets[0].GuestTeamScore > 0 ? string.Format("{0} - {1}", sets[0].HomeTeamScore, sets[0].GuestTeamScore) : "";
                var set2 = sets.Length > 1 && sets[1].HomeTeamScore > 0 && sets[1].GuestTeamScore > 0 ? string.Format("{0} - {1}", sets[1].HomeTeamScore, sets[1].GuestTeamScore) : "";
                var set3 = sets.Length > 2 && sets[2].HomeTeamScore > 0 && sets[2].GuestTeamScore > 0 ? string.Format("{0} - {1}", sets[2].HomeTeamScore, sets[2].GuestTeamScore) : "";
                if (set1 != dto.Set1 || set2 != dto.Set2 || set3 != dto.Set3)
                {
                    ctxModel.StartDate = dto.Date;
                }
            }
            #endregion
        }
Exemplo n.º 15
0
        public IHttpActionResult SetTechnicalWin(int gameId, int teamId)
        {
            GamesCycle game = _gamesRepo.GetGameCycleById(gameId);

            if (game == null)
            {
                return(NotFound());
            }

            _gamesService.SetTechnicalWinForGame(gameId, teamId);

            return(Ok());
        }
Exemplo n.º 16
0
        public IHttpActionResult EndGame(int gameId)
        {
            GamesCycle game = _gamesRepo.GetGameCycleById(gameId);

            if (game == null)
            {
                return(NotFound());
            }

            _gamesRepo.EndGame(gameId);

            return(Ok());
        }
Exemplo n.º 17
0
        public ActionResult UpdateGame(GamesCycle gc)
        {
            GamesCycle editGc = gamesRepo.GetGameCycleById(gc.CycleId);

            try
            {
                bool isChanged = false;
                if (gc.AuditoriumId != editGc.AuditoriumId)
                {
                    isChanged           = true;
                    editGc.AuditoriumId = gc.AuditoriumId;
                }
                editGc.RefereeId = gc.RefereeId;
                if (!editGc.StartDate.Equals(gc.StartDate))
                {
                    isChanged        = true;
                    editGc.StartDate = gc.StartDate;
                }

                gamesRepo.Update(editGc);
                TempData["SavedId"] = editGc.CycleId;

                if (isChanged && editGc.IsPublished)
                {
                    NotesMessagesRepo notesRep = new NotesMessagesRepo();
                    if (editGc.Stage != null && editGc.Stage.League != null && editGc.Stage.League.SeasonId != null)
                    {
                        String message = String.Format("Game details has been updated: {0} vs {1}", editGc.HomeTeam != null ? editGc.HomeTeam.Title : "", editGc.GuestTeam != null ? editGc.GuestTeam.Title : "");

                        if (editGc.HomeTeamId != null)
                        {
                            notesRep.SendToTeam((int)editGc.Stage.League.SeasonId, (int)editGc.HomeTeamId, message);
                        }
                        if (editGc.GuestTeamId != null)
                        {
                            notesRep.SendToTeam((int)editGc.Stage.League.SeasonId, (int)editGc.GuestTeamId, message);
                        }
                        if (gc.RefereeId != null)
                        {
                            notesRep.SendToUsers(new List <int> {
                                (int)editGc.RefereeId
                            }, message);
                        }
                    }

                    var notsServ = new GamesNotificationsService();
                    notsServ.SendPushToDevices(GlobVars.IsTest);
                }
            } catch (Exception e) { }
            return(RedirectToAction("Game", editGc));
        }
Exemplo n.º 18
0
        private List <GamesCycle> CreateGamesFromCombinations(List <Tuple <int, int> > combinations)
        {
            List <GamesCycle> groupGames = new List <GamesCycle>();

            foreach (var comb in combinations)
            {
                var item = new GamesCycle
                {
                    HomeTeamId  = comb.Item1,
                    GuestTeamId = comb.Item2
                };
                groupGames.Add(item);
            }
            return(groupGames);
        }
Exemplo n.º 19
0
        public static NextGameViewModel GetNextGame(IEnumerable <GamesCycle> games, int currentUserId, int leagueId, int?seasonId = null)
        {
            GamesCycle gameCycle = games.Where(g => g.GameStatus == GameStatus.Started && g.IsPublished).OrderBy(g => g.StartDate).FirstOrDefault();

            if (gameCycle == null)
            {
                gameCycle = games.Where(g => g.StartDate >= DateTime.Now && g.IsPublished).OrderBy(g => g.StartDate).FirstOrDefault();
            }

            if (gameCycle == null)
            {
                return(null);
            }

            return(ParseNextGameCycle(currentUserId, gameCycle, leagueId, seasonId));
        }
Exemplo n.º 20
0
        public ActionResult PublishGamesCycle(int gameCycleId, bool isPublished)
        {
            try
            {
                GamesCycle gameCycle = gamesRepo.GetGameCycleById(gameCycleId);
                gameCycle.IsPublished = isPublished;

                gamesRepo.Update(gameCycle);

                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, e.ToString()));
            }
        }
Exemplo n.º 21
0
        public PartialViewResult GameSetList(int id)
        {
            GamesCycle     gc   = gamesRepo.GetGameCycleById(id);
            List <GameSet> list = gc.GameSets.ToList();

            var alias = gc.Stage?.League?.Union?.Section?.Alias;

            switch (alias)
            {
            case GamesAlias.WaterPolo:
            case GamesAlias.BasketBall:
                return(PartialView("BasketBallWaterPolo/_GameSetList", list));

            default:
                return(PartialView("_GameSetList", list));
            }
        }
Exemplo n.º 22
0
 public void ResetGame(GamesCycle gc, bool includingTeams = false)
 {
     gc.TechnicalWinnnerId = null;
     db.GameSets.RemoveRange(gc.GameSets);
     gc.HomeTeamScore  = 0;
     gc.GuestTeamScore = 0;
     if (gc.PlayoffBracket != null)
     {
         gc.PlayoffBracket.WinnerId = null;
         gc.PlayoffBracket.LoserId  = null;
     }
     if (includingTeams)
     {
         gc.HomeTeamId  = null;
         gc.GuestTeamId = null;
     }
     bracketsRepo.GameEndedEvent(gc);
     gc.GameStatus = null;
     db.SaveChanges();
 }
Exemplo n.º 23
0
        public GamesCycle UpdateGameScore(GamesCycle gc)
        {
            int hScore = 0;
            int gScore = 0;

            foreach (var set in gc.GameSets)
            {
                if (set.HomeTeamScore > set.GuestTeamScore)
                {
                    hScore++;
                }
                else if (set.HomeTeamScore < set.GuestTeamScore)
                {
                    gScore++;
                }
            }
            gc.HomeTeamScore  = hScore;
            gc.GuestTeamScore = gScore;
            Update(gc);
            return(gc);
        }
Exemplo n.º 24
0
        public static GameViewModel CycleToGame(GamesCycle gamesCycle)
        {
            var vm = new GameViewModel
            {
                GameId          = gamesCycle.CycleId,
                GameCycleStatus = gamesCycle.GameStatus,
                StartDate       = gamesCycle.StartDate,
                HomeTeamId      = gamesCycle.HomeTeamId,
                HomeTeam        = gamesCycle.HomeTeam.Title,
                HomeTeamScore   = gamesCycle.HomeTeamScore,
                GuestTeam       = gamesCycle.GuestTeam.Title,
                GuestTeamId     = gamesCycle.GuestTeamId,
                GuestTeamScore  = gamesCycle.GuestTeamScore,
                Auditorium      = gamesCycle.Auditorium.Name,
                HomeTeamLogo    = gamesCycle.HomeTeam.Logo,
                GuestTeamLogo   = gamesCycle.GuestTeam.Logo,
                CycleNumber     = gamesCycle.CycleNum,
                LeagueId        = gamesCycle.Stage.LeagueId,
                LeagueName      = gamesCycle.Stage.League.Name
            };

            return(vm);
        }
Exemplo n.º 25
0
        public ActionResult UpdateGameResults(int id, bool isWaterpoloOrBasketball)
        {
            GamesCycle gc = gamesRepo.GetGameCycleById(id);

            if (gc.GameStatus != GameStatus.Ended || gc.Group.GamesType.TypeId == 1 /* Division */)
            {
                if (isWaterpoloOrBasketball)
                {
                    gamesRepo.UpdateBasketBallWaterPoloScore(id);
                }
                else
                {
                    gamesRepo.UpdateGameScore(gc);
                }
            }
            else
            {   //  If game status need to be reset after game has been ended
                //  then further games in knockout or playoff group need to be
                //  rescheduled
                gamesRepo.EndGame(gc);
            }
            return(RedirectToAction("Edit", new { @id = id }));
        }
Exemplo n.º 26
0
        private List <GamesCycle> CreateGamesForPlayoffGroup(Group group)
        {
            List <GamesCycle> games = new List <GamesCycle>();

            for (int i = 1; i <= group.NumberOfCycles; i++)
            {
                foreach (var bracket in group.PlayoffBrackets)
                {
                    GamesCycle g = new GamesCycle
                    {
                        MinPlayoffPos = bracket.MinPos,
                        MaxPlayoffPos = bracket.MaxPos,
                        GroupeId      = group.GroupId,
                        StageId       = group.StageId
                    };

                    if (bracket.Type == (int)PlayoffBracketType.Root && (bracket.Team1Id == null || bracket.Team2Id == null))
                    {
                        g.GameStatus = GameStatus.Ended;
                    }

                    if (i % 2 != 0)
                    {
                        g.HomeTeamId  = bracket.Team1Id;
                        g.GuestTeamId = bracket.Team2Id;
                    }
                    else
                    {
                        g.HomeTeamId  = bracket.Team2Id;
                        g.GuestTeamId = bracket.Team1Id;
                    }
                    bracket.GamesCycles.Add(g);
                    games.Add(g);
                }
            }
            return(games);
        }
Exemplo n.º 27
0
        public static GameSetViewModel CreateGameSet(CreateGameSetViewModel viewModel)
        {
            GamesCycle gamesCycle = _gamesRepo.GetGameCycleById(viewModel.GameCycleId);

            if (gamesCycle == null)
            {
                throw new NotFoundEntityException("Game cycle with this Id doesn't exist");
            }
            if (!gamesCycle.IsPublished)
            {
                throw new NotFoundEntityException("Game cycle with this Id doesn't published");
            }

            GameSet gameSet = new GameSet();

            gameSet.InjectFrom(viewModel);
            _gamesRepo.AddGameSet(gameSet);

            GameSetViewModel gameSetViewModel = new GameSetViewModel();

            gameSetViewModel.InjectFrom(gameSet);

            return(gameSetViewModel);
        }
Exemplo n.º 28
0
        private void SetExtendedTableScoresForGuestTeam(List <ExtendedTable> results, RankTeam guestTeam, RankTeam homeTeam, char[] alpha, ref int guestCharIndex, GamesCycle game)
        {
            var guestTeamForExtended = results.FirstOrDefault(t => t.TeamId == guestTeam.Id.Value);

            if (guestTeamForExtended == null)
            {
                guestTeamForExtended = new ExtendedTable
                {
                    TeamId   = guestTeam.Id.Value,
                    TeamName = guestTeam.Title,
                    Letter   = alpha[guestCharIndex],
                };

                results.Add(guestTeamForExtended);

                guestCharIndex++;
            }

            if (!string.IsNullOrEmpty(game.GameStatus) && game.GameStatus.Trim() == GameStatus.Ended)
            {
                guestTeamForExtended.Scores.Add(new ExtendedTableScore
                {
                    OpponentTeamId = homeTeam.Id.Value,
                    OpponentScore  = game.HomeTeamScore,
                    TeamScore      = game.GuestTeamScore
                });
            }
        }
Exemplo n.º 29
0
        public ActionResult EndGame(int id)
        {
            GamesCycle editGc = gamesRepo.EndGame(id);

            return(RedirectToAction("Edit", new { id = id }));
        }
Exemplo n.º 30
0
 public ActionResult Edit(int id, GamesCycle gc)
 {
     return(RedirectToAction("Edit", new { id = id }));
 }