示例#1
0
        private int CalculatePlayerTotal(FPLTeam teamDetails, int gwPoints)
        {
            var overallPoints = teamDetails.summary_overall_points ?? 0;
            var eventPoints   = teamDetails.summary_event_points ?? 0;
            int total         = (overallPoints - eventPoints) + gwPoints;

            return(total);
        }
示例#2
0
        private async Task <FPLTeam> GetTeamInfo(int teamId)
        {
            HttpClientHandler handler = new HttpClientHandler();

            handler = CreateHandler(handler);

            var response = await _httpClient.GetAuthAsync(handler, $"entry/{teamId}/");

            response.EnsureSuccessStatusCode();

            var content = await response.Content.ReadAsStringAsync();

            FPLTeam teamDetails = JsonConvert.DeserializeObject <FPLTeam>(content);

            return(teamDetails);
        }
示例#3
0
        public async Task <IActionResult> Index()
        {
            ViewData["Title"] = "My Team";

            var viewModel = new MyTeamViewModel();

            HttpClientHandler handler = new HttpClientHandler();

            int currentGwId = await GetCurrentGameWeekId();

            if (Request.Cookies["teamId"] == null)
            {
                teamId = await GetTeamId();
            }
            else
            {
                teamId = Convert.ToInt32(Request.Cookies["teamId"]);
            }

            var response = await _httpClient.GetAuthAsync(CreateHandler(handler), $"my-team/{teamId}");

            if (!response.IsSuccessStatusCode)
            {
                return(RedirectToAction("Error", "Home"));
            }

            //look for 404 error here

            response.EnsureSuccessStatusCode();

            var content = await response.Content.ReadAsStringAsync();

            var myTeamJSON = JObject.Parse(content);

            MyTeam myTeam = JsonConvert.DeserializeObject <MyTeam>(myTeamJSON.ToString());

            //var teamPicksJSON = AllChildren(myTeamJSON)
            //    .First(c => c.Type == JTokenType.Array && c.Path.Contains("picks"))
            //    .Children<JObject>();

            //JObject transfersObject = (JObject)myTeamJSON["transfers"];
            //TransferInfo transferInfo = transfersObject.ToObject<TransferInfo>();

            List <Pick>           teamPicks         = new List <Pick>();
            List <Pick>           teamPicksLastWeek = new List <Pick>();
            List <Transfer>       transfers         = new List <Transfer>();
            List <PlayerPosition> positions         = new List <PlayerPosition>();

            //foreach (JObject result in teamPicksJSON)
            //{
            //    Pick p = result.ToObject<Pick>();
            //    teamPicks.Add(p);
            //}

            if (currentGwId > 1)
            {
                teamPicksLastWeek = await GetLastWeeksTeam(teamPicksLastWeek, teamId, currentGwId);

                foreach (var p in myTeam.picks)
                {
                    if (teamPicksLastWeek.FindAll(x => x.element == p.element).Count == 0)
                    {
                        p.IsNewTransfer = true;
                    }
                }
            }

            int gameweekId  = currentGwId;
            var eventStatus = await GetEventStatus();

            var lastEvent       = eventStatus.status.LastOrDefault();
            var isEventFinished = false;

            if (lastEvent != null)
            {
                if (lastEvent.bonus_added && eventStatus.leagues != "Updating")
                {
                    isEventFinished = true;
                }
            }

            transfers = await GetTeamTransfers(teamId);

            positions = await GetPlayerPositionInfo();

            myTeam.picks = await AddPlayerSummaryDataToTeam(myTeam.picks, gameweekId);

            myTeam.picks = await AddPlayerGameweekDataToTeam(myTeam.picks, gameweekId);

            myTeam.picks = await CalculateTotalPointsContributed(myTeam.picks, transfers, gameweekId);

            myTeam.picks = myTeam.picks.OrderBy(x => x.position).ToList();
            FPLTeam teamDetails = await GetTeamInfo(teamId);

            var entryHistory = await GetEntryHistory(teamId, currentGwId);

            var completeEntryHistory = new CompleteEntryHistory();

            completeEntryHistory = await GetCompleteEntryHistory(completeEntryHistory, teamId);

            entryHistory = await AddExtraDatatoEntryHistory(entryHistory, completeEntryHistory);

            entryHistory.BuyingPower = CalculateTeamBuyingPower(myTeam.picks, entryHistory);

            viewModel.MyTeam      = myTeam;
            viewModel.CurrentGwId = gameweekId;
            //viewModel.Picks = teamPicks;
            viewModel.Team        = teamDetails;
            viewModel.Positions   = positions;
            viewModel.TotalPoints = teamDetails.summary_overall_points ?? 0;
            //viewModel.TransferInfo = transferInfo;
            viewModel.IsEventFinished      = isEventFinished;
            viewModel.EntryHistory         = entryHistory;
            viewModel.CompleteEntryHistory = completeEntryHistory;
            viewModel.EventStatus          = eventStatus;

            return(View(viewModel));
        }