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)); }
public async Task <IActionResult> Edit(int id, [Bind("Id, HomeScore, AwayScore")] VM_EditFixture fixture) { Boolean scoreHasChanged = false; var actualFixture = await _fixtureRepository.GetSingleFixture(id); if (id != actualFixture.Id) { return(NotFound()); } if (ModelState.IsValid) { try { if ((fixture.HomeScore != actualFixture.HomeScore) || fixture.AwayScore != actualFixture.AwayScore) { scoreHasChanged = true; } actualFixture.HomeScore = fixture.HomeScore; actualFixture.AwayScore = fixture.AwayScore; actualFixture.Result = fixture.HomeScore + " - " + fixture.AwayScore; await _fixtureRepository.SaveChanges(); if (scoreHasChanged) { var predictions = await _predictionRepository.GetPredictionsToUpdate(actualFixture.Id); PredictionHandler pp = new PredictionHandler(predictions, actualFixture); predictions = pp.updatePredictions(); } await _fixtureRepository.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!FixtureExists(actualFixture.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index", "Admin")); } return(View(fixture)); }
public void PredictionHandler_updatePredictions_awardsThreePointForCorrectResultWhenJokerPlayed() { // Arrange Prediction correctResultAndJoker = new Prediction { Id = 1, FixtureId = fixture.Id, HomeScore = 1, AwayScore = 0, Joker = true }; predictions.Add(correctResultAndJoker); ph = new PredictionHandler(predictions, fixture); // Act var result = ph.updatePredictions(); // Assert Assert.Equal(3, correctResultAndJoker.Points); }
public void PredictionHandler_updatePredictions_awardsThreePointForCorrectScore() { // Arrange Prediction correctScore = new Prediction { Id = 1, FixtureId = fixture.Id, HomeScore = 3, AwayScore = 2 }; predictions.Add(correctScore); ph = new PredictionHandler(predictions, fixture); // Act var result = ph.updatePredictions(); // Assert Assert.Equal(3, correctScore.Points); }
public void PredictionHandler_updatePredictions_awardsSixPointsForCorrectScoreWhenDoubleAndJokerPlayed() { // Arrange Prediction correctScoreAndDoubleAndJoker = new Prediction { Id = 1, FixtureId = fixture.Id, HomeScore = 5, AwayScore = 0, DoubleUp = true, Joker = true }; predictions.Add(correctScoreAndDoubleAndJoker); ph = new PredictionHandler(predictions, fixture); // Act var result = ph.updatePredictions(); // Assert Assert.Equal(6, correctScoreAndDoubleAndJoker.Points); }
public void PredictionHandler_updatePredictions_awardsZeroForIncorrectResult() { // Arrange Prediction incorrectResult = new Prediction { Id = 1, FixtureId = fixture.Id, HomeScore = 1, AwayScore = 1 }; predictions.Add(incorrectResult); ph = new PredictionHandler(predictions, fixture); // Act var result = ph.updatePredictions(); // Assert Assert.Equal(0, incorrectResult.Points); }
public void PredictionHandler_updatePredictions_awardsTwoPointsForCorrectResultWhenDoublePlayed() { // Arrange Prediction correctResultAndDouble = new Prediction { Id = 1, FixtureId = fixture.Id, HomeScore = 4, AwayScore = 0, DoubleUp = true }; predictions.Add(correctResultAndDouble); ph = new PredictionHandler(predictions, fixture); // Act var result = ph.updatePredictions(); // Assert Assert.Equal(2, correctResultAndDouble.Points); }
// 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)); }
public Classifier() { _predictionHandler = new PredictionHandler(PredictionTypes.Multiclass); _teamHandler = new TeamHandler(); Train(); }
public async Task <IActionResult> Edit(int id, VM_EditPrediction prediction) { var predictionToUpdate = await _predictionsRepository.GetSinglePrediction(id); if (predictionToUpdate == null) { return(NotFound()); } if (predictionToUpdate.ApplicationUserId != _userProvider.GetUserId()) { return(Unauthorized()); } if (predictionToUpdate.Fixture.FixtureDateTime < DateTime.Now) { return(RedirectToAction("Index", "MyPredictr")); } if (ModelState.IsValid) { try { var currentPredictions = await _predictionsRepository.GetAll(); PredictionHandler ph = new PredictionHandler(currentPredictions, _userProvider.GetUserId()); int doublesUsed = ph.CountDoublesPlayed(); int jokersUsed = ph.CountJokersPlayed(); predictionToUpdate.HomeScore = prediction.HomeScore; predictionToUpdate.AwayScore = prediction.AwayScore; if (jokersUsed < 3 || prediction.Joker == false) { predictionToUpdate.Joker = prediction.Joker; } else { if (predictionToUpdate.Joker == true) { predictionToUpdate.Joker = prediction.Joker; } else { // back to the offending prediction return(RedirectToAction("Edit", "Predictions", new { id })); // redirect to create prediction } } if (doublesUsed < 3 || prediction.DoubleUp == false) { predictionToUpdate.DoubleUp = prediction.DoubleUp; } else { if (predictionToUpdate.DoubleUp == true) { predictionToUpdate.DoubleUp = prediction.DoubleUp; } else { // back to the offending prediction return(RedirectToAction("Edit", "Predictions", new { id })); // redirect to create prediction } } predictionToUpdate.Joker = prediction.Joker; predictionToUpdate.DoubleUp = prediction.DoubleUp; _predictionsRepository.Update(predictionToUpdate); await _predictionsRepository.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PredictionExists(id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index", "MyPredictr")); } return(View(prediction)); }
// GET: Predictions/Edit/5 public async Task <IActionResult> Edit(int id) { var prediction = await _predictionsRepository.GetSinglePrediction(id); if (prediction == null) { return(NotFound()); } if (prediction.Fixture.FixtureDateTime < DateTime.Now) { return(RedirectToAction("Index", "MyPredictr")); } if (prediction.ApplicationUserId != _userProvider.GetUserId()) { return(Unauthorized()); } VM_EditPrediction vm = new VM_EditPrediction(); var currentPredictions = await _predictionsRepository.GetAll(); PredictionHandler ph = new PredictionHandler(currentPredictions, _userProvider.GetUserId()); int doublesUsed = ph.CountDoublesPlayed(); int jokersUsed = ph.CountJokersPlayed(); vm.HomeTeam = prediction.Fixture.Home; vm.AwayTeam = prediction.Fixture.Away; vm.HomeScore = prediction.HomeScore; vm.AwayScore = prediction.AwayScore; vm.Joker = prediction.Joker; vm.DoubleUp = prediction.DoubleUp; if (jokersUsed < 3) { vm.JokerDisabled = false; } else { if (prediction.Joker == true) { vm.JokerDisabled = false; } else { vm.JokerDisabled = true; } } if (doublesUsed < 3) { vm.DoubleUpDisabled = false; } else { if (prediction.DoubleUp == true) { vm.DoubleUpDisabled = false; } else { vm.DoubleUpDisabled = true; } } return(View(vm)); }