예제 #1
0
        public ActionResult UpdateFinishedGamePost(UpdateFinishedGameViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                var allTeams = this.games.GetAll()
                               .Where(g => g.Date < DateTime.Now)
                               .ToList()
                               .OrderBy(g => g.Date);

                model.Games = new List <SelectListItem>();
                foreach (var game in allTeams)
                {
                    model.Games.Add(new SelectListItem
                    {
                        Text  = game.Date.ToString("dd.MM.yy HH:mm") + "  |  " + game.HostTeam.Replace('_', ' ') + " - " + game.GuestTeam.Replace('_', ' ') + " " + game.FinalResult,
                        Value = game.Id.ToString()
                    });
                }

                return(this.View(model));
            }

            var dataModel = AutoMapper.Mapper.Map <UpdateFinishedGameViewModel, LesGamblers.Models.Game>(model);

            this.games.UpdateGame(dataModel, model.Id);
            PointsUpdater.CheckCorrectPredictions(model, this.predictions, this.gamblers);

            this.TempData["Notification"] = "The game was updated successfully!";
            return(RedirectToAction("UpdateFinishedGame", "Games"));
        }
예제 #2
0
        private static int CheckCorrectGoalscorer(UpdateFinishedGameViewModel model, string predictedGoalscorer)
        {
            if (string.IsNullOrEmpty(predictedGoalscorer) && string.IsNullOrEmpty(model.Goalscorers))
            {
                return(LesGamblers.Common.GlobalConstants.SignFinalResultOrGoalscorerPredictionPoints);
            }
            else if (string.IsNullOrEmpty(predictedGoalscorer))
            {
                return(LesGamblers.Common.GlobalConstants.ZeroPoints);
            }

            var actualGoalscorers = new string[predictedGoalscorer.Where(x => x == ',').Count() + 1];

            if (model.Goalscorers != null)
            {
                actualGoalscorers = model.Goalscorers.Trim().Split(new string[] { "," }, StringSplitOptions.None).ToArray();
            }

            var goalscorerPredictedCorrectly = actualGoalscorers.Contains(predictedGoalscorer);

            if (goalscorerPredictedCorrectly)
            {
                var scorersGoalsCount = new Dictionary <string, int>();
                var mostGoals         = 0;
                foreach (var scorer in actualGoalscorers)
                {
                    if (!scorersGoalsCount.ContainsKey(scorer))
                    {
                        scorersGoalsCount.Add(scorer, 1);
                    }
                    else
                    {
                        scorersGoalsCount[scorer]++;
                    }

                    if (mostGoals < scorersGoalsCount[scorer])
                    {
                        mostGoals = scorersGoalsCount[scorer];
                    }
                }

                var topScorers = scorersGoalsCount.Where(x => x.Value == mostGoals).Select(x => x.Key).ToList();
                if (topScorers.Contains(predictedGoalscorer))
                {
                    return(LesGamblers.Common.GlobalConstants.SignFinalResultOrGoalscorerPredictionPoints);
                }
            }

            return(LesGamblers.Common.GlobalConstants.ZeroPoints);
        }
예제 #3
0
        public ActionResult UpdateFinishedGame(UpdateFinishedGameViewModel model)
        {
            var allTeams = this.games.GetAll()
                           //.Where(g => g.Date < DateTime.Now)
                           .ToList()
                           .OrderBy(g => g.Date);

            model.Games = new List <SelectListItem>();
            foreach (var game in allTeams)
            {
                model.Games.Add(new SelectListItem
                {
                    Text  = game.Date.ToString("dd.MM.yy HH:mm") + "  |  " + game.HostTeam.Replace('_', ' ') + " - " + game.GuestTeam.Replace('_', ' ') + " " + game.FinalResult,
                    Value = game.Id.ToString()
                });
            }

            return(this.View(model));
        }
예제 #4
0
        public static void CheckCorrectPredictions(UpdateFinishedGameViewModel model, IPredictionsService predictions, IGamblersService gamblers)
        {
            var realFinalResult = model.FinalResult.Split(new char[] { ':', '-' }).ToArray();
            var homeTeamGoals   = int.Parse(realFinalResult[0]);
            var guestTeamGoals  = int.Parse(realFinalResult[1]);

            var currentGamePredictions = predictions.GetAll().Where(p => p.GameId == model.Id).ToList();

            foreach (var prediction in currentGamePredictions)
            {
                currentPredictionPoints = 0;
                var finalResult              = prediction.FinalResult.Split(new char[] { ':', '-' }).ToArray();
                var homeTeamGoalsPrediction  = int.Parse(finalResult[0]);
                var guestTeamGoalsPrediction = int.Parse(finalResult[1]);
                var updatedPrediction        = new UpdatePredictionPointsViewModel();

                updatedPrediction.FinalResultPredicted = CheckIfResultIsCorrectlyPredicted(homeTeamGoals, guestTeamGoals, homeTeamGoalsPrediction, guestTeamGoalsPrediction);
                if (!updatedPrediction.FinalResultPredicted)
                {
                    updatedPrediction.SignPredicted = CheckIfSignIsCorrectlyPredicted(homeTeamGoals, guestTeamGoals, homeTeamGoalsPrediction, guestTeamGoalsPrediction);
                }
                else
                {
                    updatedPrediction.SignPredicted = true;
                }

                var goalscorerPredictionPoints = CheckCorrectGoalscorer(model, prediction.Goalscorer);
                currentPredictionPoints += goalscorerPredictionPoints;
                if (goalscorerPredictionPoints > 0)
                {
                    updatedPrediction.GoalscorerPredicted = true;
                }

                var currentPrediction = predictions.GetById(prediction.Id).FirstOrDefault();
                updatedPrediction.TotalPoints = currentPredictionPoints;
                var dataModel = AutoMapper.Mapper.Map <UpdatePredictionPointsViewModel, LesGamblers.Models.Prediction>(updatedPrediction);

                predictions.UpdatePrediction(dataModel, prediction.Id);
            }
        }