Esempio n. 1
0
        public VM_CreatePrediction BuildCreateVMPrediction()
        {
            VM_CreatePrediction vm = new VM_CreatePrediction();

            int doublesUsed = CountDoublesPlayed();
            int jokersUsed  = CountJokersPlayed();



            vm.HomeTeam = _fixture.Home;
            vm.AwayTeam = _fixture.Away;

            if (jokersUsed < 3)
            {
                vm.JokerDisabled = false;
            }
            else
            {
                vm.JokerDisabled = true;
            }

            if (doublesUsed < 3)
            {
                vm.DoubleUpDisabled = false;
            }
            else
            {
                vm.DoubleUpDisabled = true;
            }

            return(vm);
        }
        public async Task <IActionResult> Create(VM_CreatePrediction prediction, int id)
        {
            if (ModelState.IsValid)
            {
                VM_CreatePrediction _prediction = prediction;

                Prediction _fullPrediction = new Prediction();

                String currentUserId = _userProvider.GetUserId();

                var currentPredictions = await _predictionsRepository.GetAll();

                PredictionHandler ph = new PredictionHandler(currentPredictions, currentUserId);

                int doublesUsed = ph.CountDoublesPlayed();
                int jokersUsed  = ph.CountJokersPlayed();

                var fixture = await _fixturesRepository.GetSingleFixture(id);

                if (fixture.FixtureDateTime < DateTime.Now)
                {
                    return(RedirectToAction("Index", "MyPredictr"));
                }

                _fullPrediction.ApplicationUserId = currentUserId;
                _fullPrediction.FixtureId         = id;
                _fullPrediction.HomeScore         = prediction.HomeScore;
                _fullPrediction.AwayScore         = prediction.AwayScore;

                if (jokersUsed < 3 || prediction.Joker == false)
                {
                    _fullPrediction.Joker = prediction.Joker;
                }
                else if (jokersUsed == 3 && _prediction.Joker == true)
                {
                    // back to the offending prediction
                    return(RedirectToAction("Create", "Predictions", new { id })); // redirect to create prediction
                }

                if (doublesUsed < 3 || prediction.DoubleUp == false)
                {
                    _fullPrediction.DoubleUp = prediction.DoubleUp;
                }

                else if (doublesUsed == 3 && _prediction.DoubleUp == true)
                {
                    // back to the offending prediction
                    return(RedirectToAction("Create", "Predictions", new { id }));
                }


                _predictionsRepository.Add(_fullPrediction);
                await _predictionsRepository.SaveChanges();

                return(RedirectToAction("Index", "MyPredictr"));
            }
            return(View(prediction));
        }
        // GET: Predictions/Create
        public async Task <IActionResult> Create(int id)
        {
            var fixture = await _fixturesRepository.GetSingleFixture(id);

            if (fixture.FixtureDateTime < DateTime.Now)
            {
                return(RedirectToAction("Index", "MyPredictr"));
            }

            if (fixture == null)
            {
                return(NotFound());
            }

            var currentPredictions = await _predictionsRepository.GetAll();

            PredictionHandler ph = new PredictionHandler(currentPredictions, _userProvider.GetUserId());

            VM_CreatePrediction _vm = ph.BuildCreateVMPrediction();

            return(View("Create", _vm));
        }