Esempio n. 1
0
        public ActionResult AddPrediction(int PlayerId, int WeekId, AddPredictionInputs inputs)
        {
            try
            {
                var player = GetRepository<Player>().Get(PlayerId);
                var week = GetRepository<Week>().Get(WeekId);
                var League = GetRepository<League>().All().First();

                Match selectedMatch = week.FindMatch(inputs.MatchId);

                PlayerPrediction playerPrediction = player.CreatePrediction(selectedMatch, SystemDate.Current());

                League.AddPrediction(week, BensBoxing.Web.Core.Helpers.ControllerHelpers.SetPrediction(inputs, playerPrediction));
                var response = new AddPredictionResult
                {
                    MatchId = inputs.MatchId,
                    Success = true,
                    SummaryText = playerPrediction.ToTextSummary()
                };

                return Json(response);
            }
            catch (Exception ex)
            {
                var response = new AddPredictionResult
                {
                    MatchId = inputs.MatchId,
                    Success = false,
                    SummaryText = "N/A"
                };

                return Json(response);
            }
        }
        public ActionResult AddPrediction(AddPredictionInputs inputs)
        {
            try
            {
                var player = GetPlayer();

                var season = GetActiveSeason();
                var week = season.GetWeekSeason(SystemDate.Current());
                Match selectedMatch = week.FindMatch(inputs.MatchId);

                PlayerPrediction playerPrediction = player.CreatePrediction(selectedMatch, SystemDate.Current());

                GetLeague().AddPrediction(week, BensBoxing.Web.Core.Helpers.ControllerHelpers.SetPrediction(inputs, playerPrediction));
                DataSession.Save(playerPrediction);

                var response = new AddPredictionResult
                {
                    MatchId = inputs.MatchId,
                    Success = true,
                    SummaryText = playerPrediction.ToTextSummary()
                };

                return Json(response);
            }
            catch (Exception ex)
            {
                var response = new AddPredictionResult
                {
                    MatchId = inputs.MatchId,
                    Success = false,
                    SummaryText = "N/A"
                };

                return Json(response);
            }
        }
        public PlayerPrediction SetPrediction(AddPredictionInputs inputs, PlayerPrediction prediction)
        {
            if (inputs.PredictionType == "Winner")
            {
                var boxer = prediction.Match.Boxers.Single(b => b.Id == inputs.Winner);

                if (inputs.ByKnockOut)
                {
                    prediction.WinByKnockout(boxer, inputs.Round);
                }

                if (inputs.ByPoints)
                {
                    prediction.WinByPoints(boxer, inputs.Decision.Value);
                }
            }

            if (inputs.PredictionType == "Draw")
            {
                prediction.PredictAsDraw();
            }

            return prediction;
        }