Beispiel #1
0
        public async Task <List <PlacesModel> > GetPlacesPredictions(string input)
        {
            HttpClient          client           = new HttpClient();
            PredictionsModel    predictionsModel = new PredictionsModel();
            HttpResponseMessage placesResponse;


            strPlacesAPI = strPlacesAPI.Replace("{{pred}}", input);

            placesResponse = client.GetAsync(strPlacesAPI).Result;

            if (placesResponse.IsSuccessStatusCode)
            {
                predictionsModel = await placesResponse.Content.ReadAsAsync <PredictionsModel>();
            }


            PlacesModel        placesModel;
            List <PlacesModel> placesList = new List <PlacesModel>();

            foreach (Prediction p in predictionsModel.predictions)
            {
                placesModel             = new PlacesModel();
                placesModel.description = p.description;
                placesList.Add(placesModel);
            }

            return(placesList);
        }
        public ActionResult Predictions(int selectedLeagueId = -1, int selectedSeasonId = -1, PredictionsType type = PredictionsType.All)
        {
            PredictionsModel model = new PredictionsModel();

            try
            {
                model.Leagues        = client.GetAllLeagues();
                model.SelectedLeague = selectedLeagueId == -1
                        ? model.Leagues.FirstOrDefault()
                        : model.Leagues.Where(l => l.LeagueId == selectedLeagueId).FirstOrDefault();
                selectedLeagueId = model.SelectedLeague?.LeagueId ?? -1;

                if (selectedLeagueId == -1)
                {
                    return(View(model));
                }

                model.Seasons        = client.GetAllLeagueSeasons(selectedLeagueId).OrderByDescending(s => s.StartYear).ToList();
                model.SelectedSeason = selectedSeasonId == -1
                        ? model.Seasons.FirstOrDefault()
                        : model.Seasons.Where(s => s.LeagueSeasonId == selectedSeasonId).FirstOrDefault();
                selectedSeasonId = model.SelectedSeason?.LeagueSeasonId ?? -1;

                if (selectedSeasonId == -1)
                {
                    return(View(model));
                }

                PredictionsResponseDto predictionResponse = null;
                switch (type)
                {
                case PredictionsType.All:
                    predictionResponse = client.GetAllSeasonPredictions(selectedSeasonId);
                    break;

                case PredictionsType.Current:
                    predictionResponse = client.GetCurrentSeasonPredictions(selectedSeasonId);
                    break;

                case PredictionsType.Finished:
                    predictionResponse = client.GetFinishedSeasonPredictions(selectedSeasonId);
                    break;

                default:
                    throw new Exception("Unknown PredictionsType");
                }

                model.SelectedPredictionsType = type;
                model.Predictions             = predictionResponse.Predictions;
            }
            catch (Exception ex)
            {
                //log exception
                //return ErrorPage
                model.Error = ex.Message;
                return(View(model));
            }
            return(View(model));
        }
Beispiel #3
0
        public PartialViewResult ShowPredictions()
        {
            string team1 = Request.Form["team1"];
            string team2 = Request.Form["team2"];

            PredictionsModel predictionsModel = new PredictionsModel(team1, team2);

            if (predictionsModel.Team1 == null || predictionsModel.Team2 == null)
            {
                return(PartialView("_Error"));
            }

            predictionsModel.Predict();

            return(PartialView("_ShowPredictions", predictionsModel));
        }