示例#1
0
        public IEnumerable <PersonStatistics> Get(int id)
        {
            if (!ModelState.IsValid)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(null);
            }

            gameBll.FillRounds = true;
            Game game = gameBll.GetGame(id);

            if (game == null)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(null);
            }

            ProtocolGameViewModel oldProtocolView = GetDefaultProtocol(game);

            IEnumerable <int> personIds = GetAllPersonIdsFromBothProtocols(oldProtocolView, new ProtocolGameViewModel());

            personBll.FillPersonCareer = true;
            IEnumerable <Person> persons = personBll.GetPersons(personIds);

            IEnumerable <PersonStatistics> personStatistics = personStatisticsBll.CalculateTourneyStatistics(game.round.tourneyId, persons);

            personStatisticsBll.SavePersonStatistics(game.round.tourneyId, personStatistics);

            return(personStatistics);
        }
        private ProtocolGameViewModel BuildViewModel()
        {
            var protocolViewModel = new ProtocolGameViewModel();

            protocolViewModel.home.teamId       = GetTeamId(Side.Home);
            protocolViewModel.home.playersAll   = GetPersons(Side.Home);
            protocolViewModel.home.playersSquad = protocolViewModel.home.playersAll;
            protocolViewModel.home.playersSubs  = protocolViewModel.home.playersAll;
            protocolViewModel.home.main         = GetMain(Side.Home);
            protocolViewModel.home.reserve      = GetReserve(Side.Home);
            protocolViewModel.home.goals        = GetGoals(Side.Home);
            protocolViewModel.home.subs         = GetSubstitutions(Side.Home);
            protocolViewModel.home.cards        = GetCards(Side.Home);
            protocolViewModel.home.others       = GetOthers(Side.Home);

            protocolViewModel.away.teamId       = GetTeamId(Side.Away);
            protocolViewModel.away.playersAll   = GetPersons(Side.Away);
            protocolViewModel.away.playersSquad = protocolViewModel.away.playersAll;
            protocolViewModel.away.playersSubs  = protocolViewModel.away.playersAll;
            protocolViewModel.away.main         = GetMain(Side.Away);
            protocolViewModel.away.reserve      = GetReserve(Side.Away);
            protocolViewModel.away.goals        = GetGoals(Side.Away);
            protocolViewModel.away.subs         = GetSubstitutions(Side.Away);
            protocolViewModel.away.cards        = GetCards(Side.Away);
            protocolViewModel.away.others       = GetOthers(Side.Away);

            protocolViewModel.fake = gameNoteBuilder.FakeProtocol;

            return(protocolViewModel);
        }
示例#3
0
        private IEnumerable <int> GetAllPersonIdsFromBothProtocols(ProtocolGameViewModel oldProtocol, ProtocolGameViewModel newProtocol)
        {
            List <int> allPersonIds =
                oldProtocol.home.playersAll != null
                ? oldProtocol.home.playersAll.Select(p => p.id).ToList()
                : new List <int>();

            IEnumerable <PersonViewModel> oldAwayPersonModels = oldProtocol.away.playersAll ?? new List <PersonViewModel>();

            allPersonIds.AddRange(oldAwayPersonModels.Where(m => !allPersonIds.Contains(m.id)).Select(p => p.id));

            IEnumerable <PersonViewModel> newHomePersonModels = newProtocol.home.playersAll ?? new List <PersonViewModel>();

            allPersonIds.AddRange(newHomePersonModels.Where(m => !allPersonIds.Contains(m.id)).Select(p => p.id));

            IEnumerable <PersonViewModel> newAwayPersonModels = newProtocol.away.playersAll ?? new List <PersonViewModel>();

            allPersonIds.AddRange(newAwayPersonModels.Where(m => !allPersonIds.Contains(m.id)).Select(p => p.id));

            return(allPersonIds);
        }
        public static IEnumerable <ProtocolRecord> ToRecordsList(this ProtocolGameViewModel protocolViewModel)
        {
            if (protocolViewModel == null)
            {
                return(new ProtocolRecord[0]);
            }

            var protocolRecords = new List <ProtocolRecord>();

            if (protocolViewModel.home != null)
            {
                protocolRecords.AddRange(GetProtocolTeamRecords(protocolViewModel.home));
            }

            if (protocolViewModel.away != null)
            {
                protocolRecords.AddRange(GetProtocolTeamRecords(protocolViewModel.away));
            }

            return(protocolRecords);
        }
示例#5
0
        public IEnumerable <PersonStatistics> Post(int id, [FromBody] ProtocolGameViewModel protocolView)
        {
            if (!ModelState.IsValid)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(null);
            }

            gameBll.FillRounds = true;
            Game game = gameBll.GetGame(id);

            if (game == null)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(null);
            }

            ProtocolGameViewModel oldProtocolView = GetDefaultProtocol(game);

            var records = protocolView.ToRecordsList();

            int count = protocolBll.SaveProtocol(id, records);

            var gameNoteBuilder = new GameNoteBuilder(game);

            gameNoteBuilder.FakeProtocol = protocolView.fake;

            gameBll.SaveGame(gameNoteBuilder.Game);

            IEnumerable <int> personIds = GetAllPersonIdsFromBothProtocols(oldProtocolView, new ProtocolGameViewModel());

            personBll.FillPersonCareer = true;
            IEnumerable <Person> persons = personBll.GetPersons(personIds);

            IEnumerable <PersonStatistics> personStatistics = personStatisticsBll.CalculateTourneyStatistics(game.round.tourneyId, persons);

            personStatisticsBll.SavePersonStatistics(game.round.tourneyId, personStatistics);

            return(personStatistics);
        }