Exemple #1
0
        public ActionResult AddPredictionPost(AddPredictionViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }
            model.FinalResult = model.FinalResult.Trim();

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

            var currentGambler = this.gamblers.GetByUsername(this.User.Identity.Name).FirstOrDefault();

            dataModel.Gambler = currentGambler;

            var alreadyPredictedMatch = this.predictions.GetAll()
                                        .Where(p => p.GamblerId == currentGambler.Id && p.GameId.ToString() == model.GameId)
                                        .ToList();

            if (alreadyPredictedMatch.Count() > 0)
            {
                this.predictions.UpdatePrediction(dataModel, alreadyPredictedMatch.FirstOrDefault().Id);
                this.TempData["Notification"] = "Your prediction was updated successfully! Good luck!";
            }
            else
            {
                this.predictions.Add(dataModel);
                this.TempData["Notification"] = "Your prediction was added successfully! Good luck!";
            }

            return(RedirectToAction("Index", "Home"));
        }
Exemple #2
0
        //[OutputCache(Duration = 60 * 60)]
        public ActionResult AddPredictionCachedData()
        {
            var startRange     = DateTime.Now + new TimeSpan(1, 0, 0);     // 1 hour before match start
            var endRange       = DateTime.Now + new TimeSpan(13, 0, 0, 0); // 13 days after now
            var availableGames = this.games
                                 .GetAll()
                                 .Where(g => string.IsNullOrEmpty(g.FinalResult) && g.Date > startRange && g.Date < endRange)
                                 .OrderBy(g => g.Date)
                                 .ToList();

            AddPredictionViewModel model = new AddPredictionViewModel();

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

            return(this.View(model));
        }