public Scores(Frame mainFrame) { this.InitializeComponent(); this.mainFrame = mainFrame; this.hsvm = new HighScoreViewModel(); this.DataContext = this.hsvm; }
// GET: Admin/HighScore public ActionResult Index() { var model = new List <HighScoreViewModel>(); var allQuizzes = QuizDb.Quizzes.ToList(); foreach (var quiz in allQuizzes) { var gameModel = new HighScoreViewModel(); gameModel.Quiz = quiz; gameModel.Games = QuizDb.QuizGames.Where(x => x.Levels.Any(y => y.Quiz.Id == quiz.Id)).ToList();; gameModel.Players = QuizDb.GamePlayers.Where(x => x.Game.Levels.Any(y => y.Quiz.Id == quiz.Id)).Select(x => x.UserId).Distinct().ToList(); gameModel.Logs = QuizDb.GameLogs.Where(x => x.Game.Levels.Any(y => y.Quiz.Id == quiz.Id)).ToList(); model.Add(gameModel); } return(View(model)); }
public IActionResult HighScores() { var hsm = new HighScoreViewModel(); hsm.HighScores = HighScoreRepo.GetHighScores(); return(View(hsm)); }
public async Task <string> UpdateHighscore(HighScoreViewModel newHighscore) { var highscores = _projectContext.Highscores.ToList(); var updateHighscore = await _projectContext.Highscores.FindAsync(newHighscore.HighscoreId); if (updateHighscore == null) { return("Error while updating."); } if (updateHighscore.Score > newHighscore.Score) { return("Score was too low. Cannot replace highscore."); } if (updateHighscore.Score == newHighscore.Score) { return("The score is the same."); } updateHighscore.Score = newHighscore.Score; updateHighscore.Email = newHighscore.Email; updateHighscore.DateAttained = newHighscore.DateAttained; await _projectContext.SaveChangesAsync(); return("Succesfully Updated."); }
public DatabaseService() { var Item1 = new HighScoreViewModel(); Item1.HighScoreId = Guid.Parse("98e7a84f-1f5b-42d1-9edb-73eefb6b0b20"); Item1.PersonId = Guid.Parse("e4b62de3-d8ad-4439-b9da-b1e47956137a"); Item1.Score = 5020; Item1.DateOfScore = new DateTime(2019, 2, 11); var Item2 = new HighScoreViewModel(); Item2.HighScoreId = Guid.Parse("21b799e0-cef5-448e-8b8a-5212998b29c9"); Item2.PersonId = Guid.Parse("e4b62de3-d8ad-4439-b9da-b1e47956137a"); Item2.Score = 7852; Item2.DateOfScore = new DateTime(2019, 2, 11); var Item3 = new HighScoreViewModel(); Item3.HighScoreId = Guid.Parse("ea5c96d3-fd9d-46ab-8809-756a420623ce"); Item3.PersonId = Guid.Parse("e4b62de3-d8ad-4439-b9da-b1e47956137a"); Item3.Score = 6845; Item3.DateOfScore = new DateTime(2019, 2, 11); TestData.Add(Item1); TestData.Add(Item2); TestData.Add(Item3); }
public void CreateHighScore_UpdateHighScore_RetrieveLeaderBoard_ValidateNewScoreOnLb_ValidateOtherScoresOnLb_ReturnsTrue() { // setup var highScoreService = _mocker.Create <HighScoreService>(); HighScoreViewModel newScore = new HighScoreViewModel { HighScoreId = Guid.Parse("9bf3b5c2-9eaa-425b-b0be-e884cfc3d6f0"), PersonId = Guid.Parse("84b4ecb4-569f-4b4e-b234-7c79fcd0a360"), Score = 600, DateAttained = DateTime.Today }; // Get leaderboard List <HighScoreViewModel> leaderboard = highScoreService.GetTopScores(); // Search for new score var foundScore = leaderboard.Find(x => x.PersonId == newScore.PersonId); // Assert // Verify creation is successful Assert.AreEqual(1, highScoreService.UpdateHighScore(newScore)); // Verify new score is the same as created score Assert.AreEqual(foundScore.PersonId, newScore.PersonId); }
// Creates list of fake scores to return public List <HighScoreViewModel> GetTopScores() { HighScoreViewModel scoreOne = new HighScoreViewModel { HighScoreId = Guid.Parse("9bf3b5c2-9eaa-425b-b0be-e884cfc3d6f0"), PersonId = Guid.Parse("84b4ecb4-569f-4b4e-b234-7c79fcd0a360"), Score = 500, DateAttained = DateTime.Today }; HighScoreViewModel scoreTwo = new HighScoreViewModel { HighScoreId = Guid.Parse("8a51e016-bbd6-4799-a7bc-5e57aea8b5a0"), PersonId = Guid.Parse("dc31053b-c68e-4e75-9b4d-805b6890ee26"), Score = 400, DateAttained = DateTime.Today }; HighScoreViewModel scoreThree = new HighScoreViewModel { HighScoreId = Guid.Parse("35320618-cb3d-4a54-ac86-fd81eff71371"), PersonId = Guid.Parse("0354e35a-3a17-4008-8572-52cdfed9219b"), Score = 300, DateAttained = DateTime.Today }; List <HighScoreViewModel> scoreList = new List <HighScoreViewModel> { scoreOne, scoreTwo, scoreThree }; return(scoreList); }
public async Task <IActionResult> PutHighScoreViewModel([FromRoute] int id, [FromBody] HighScoreViewModel highScoreViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != highScoreViewModel.ScoreId) { return(BadRequest()); } _context.Entry(highScoreViewModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HighScoreViewModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public string UpdateHighscore(Guid personId, decimal newHighscore, HighScoreViewModel previousViewModel) { HighScoreViewModel newHighscoreModel = new HighScoreViewModel { PersonId = personId, Score = newHighscore, DateAttained = DateTime.Now }; return(UpdateHighscore(newHighscoreModel, previousViewModel)); }
public string UpdateHighscore(HighScoreViewModel newHighscore, HighScoreViewModel previousViewModel) { if (previousViewModel.Score > newHighscore.Score) { return("Score was too low. Cannot replace highscore."); } else { return("Succesfully Updated."); } }
public async Task <IActionResult> PostHighScoreViewModel([FromBody] HighScoreViewModel highScoreViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.HighScores.Add(highScoreViewModel); await _context.SaveChangesAsync(); return(CreatedAtAction("GetHighScoreViewModel", new { id = highScoreViewModel.ScoreId }, highScoreViewModel)); }
public async Task <int> CreateHighScore(HighScoreViewModel newHighScore) { _personContext.Scores.Add(new HighScore { HighScoreId = Guid.NewGuid(), PersonId = newHighScore.PersonId, Score = newHighScore.Score, DateAttained = newHighScore.DateAttained }); return(await _personContext.SaveChangesAsync()); }
//private readonly IQuizTakingRepository _quizTakingRepository = new SqlDbQuizTakingRepository(); public ActionResult Index() { var quizTakings = _quizTakingRepository.GetAll(); var model = HighScoreViewModel.MapFromDataModel(quizTakings); model.ForEach(LoadRelationshipProperties); model = model .OrderByDescending(o => o.Score) .ThenBy(o => o.Ended); return(View("Index", model)); }
public async Task <IActionResult> PostHighScoreViewModel([FromBody] HighScoreViewModel highScoreViewModel) { if (!ModelState.IsValid) { _logger.LogWarning("Model state invalid"); return(BadRequest(ModelState)); } _context.HighScoreViewModel.Add(highScoreViewModel); await _context.SaveChangesAsync(); _logger.LogInformation("New High score successfully created "); return(CreatedAtAction("GetHighScoreViewModel", new { id = highScoreViewModel.ScoreId }, highScoreViewModel)); }
public async Task <HighScoreViewModel> GetHighscore(Guid personId) { var highscore = await _highScoreOrchestrator.GetHighscore(personId); var highscoreModel = new HighScoreViewModel { HighscoreId = highscore.HighscoreId, PersonId = highscore.PersonId, Email = highscore.Email, Score = highscore.Score, DateAttained = DateTime.Now }; return(highscoreModel); }
//Takes PersonViewModel and returns HighScore - Currently Unused public HighScoreViewModel GetHighScorePersonId(PersonViewModel person) { var highScoreEntity = _gamesContext.HighScores .Where(x => x.PersonId == person.PersonId) .OrderByDescending(x => x.Score) .FirstOrDefault(); var viewModel = new HighScoreViewModel { PersonId = highScoreEntity.PersonId, Score = highScoreEntity.Score, DateAttained = highScoreEntity.DateAttained }; return(viewModel); }
public async Task <bool> UpdateDatabase(HighScoreViewModel ItemToAdd) { var Update = await _scorecontext.HighScore.FindAsync(ItemToAdd.PersonId); if (Update == null) { return(false); } Update.score = (int)ItemToAdd.Score; Update.personId = ItemToAdd.PersonId; Update.highScoreId = ItemToAdd.HighScoreId; Update.dateAttained = ItemToAdd.DateOfScore; await _scorecontext.SaveChangesAsync(); return(true); }
public async Task <int> UpdateHighscore(Guid personID, int newHighScore) { // get list of current top scores List <HighScoreViewModel> currentHighScores = GetTopScores(); // find high score player already has HighScoreViewModel currentPlayerScore = currentHighScores.Find(x => x.PersonId.Equals(personID)); // update high score and save to db var saved = await _highScoreOrchestrator.UpdateHighScore(new HighScoreViewModel { PersonId = personID, Score = newHighScore, DateAttained = DateTime.Now }); // Should always return 1. return(saved); }
// returns -1 for error, 0 for no update, and 1 for successfully updated public async Task <int> UpdateHighScore(HighScoreViewModel updateHighScore) { var searchScore = await _personContext.Scores.FindAsync(updateHighScore.PersonId); if (searchScore == null) { return(-1); } if (searchScore.Score >= updateHighScore.Score) { return(0); } searchScore.HighScoreId = updateHighScore.HighScoreId; searchScore.Score = updateHighScore.Score; searchScore.DateAttained = updateHighScore.DateAttained; return(1); }
public List <HighScoreViewModel> GetScores(List <HighScoreViewModel> score) { //var score = _scorecontext.HighScore.Select(x => new HighScoreViewModel //{ // Score = x.score, // DateOfScore = x.dateAttained, // HighScoreId = x.highScoreId, // PersonId = x.personId //}).ToList(); var sortedlist = new List <HighScoreViewModel>(); while (score.Count != 0) { decimal highest = score[0].Score; int highindex = 0; for (int index = 1; index < score.Count; index++) { if (score[index].Score >= highest) { highindex = index; highest = score[highindex].Score; } } var item = new HighScoreViewModel(); item.DateOfScore = score[highindex].DateOfScore; item.HighScoreId = score[highindex].HighScoreId; item.PersonId = score[highindex].PersonId; item.Score = score[highindex].Score; sortedlist.Add(item); score.RemoveAt(highindex); } return(sortedlist); }
public HighScoreViewModel CreateHighScore(PersonViewModel person, decimal score) { var highScoreViewModel = new HighScoreViewModel { HighScoreId = Guid.NewGuid(), PersonId = person.PersonId, Score = score, DateAttained = DateTime.Now }; _gamesContext.HighScores.Add(new HighScore { HighScoreId = highScoreViewModel.HighScoreId, PersonId = highScoreViewModel.PersonId, Score = highScoreViewModel.Score, DateAttained = highScoreViewModel.DateAttained }); _gamesContext.SaveChanges(); return(highScoreViewModel); }
public HighScoreViewModel UpdateScore(Decimal score, Guid name, List <HighScoreViewModel> Databaseresults, out HighScoreViewModel newperson) { var PersonToChange = Databaseresults.Find(x => x.PersonId == name); if (PersonToChange == null) { var NewPerson = new HighScoreViewModel(); NewPerson.DateOfScore = DateTime.Now; NewPerson.HighScoreId = Guid.NewGuid(); NewPerson.Score = score; NewPerson.PersonId = name; newperson = NewPerson; return(NewPerson); } else { if (PersonToChange.Score < score) { var updateEntity = new HighScoreViewModel(); updateEntity.PersonId = PersonToChange.PersonId; updateEntity.Score = (int)score; updateEntity.DateOfScore = DateTime.Now; updateEntity.HighScoreId = PersonToChange.HighScoreId; newperson = null; return(updateEntity); } else { newperson = null; return(PersonToChange); } } }
public async Task <string> UpdateHighscore(string email, string newHighscore) { decimal newHighscoreDecimal = decimal.Parse(newHighscore); PersonOrchestrator pO = new PersonOrchestrator(); List <PersonViewModel> currentPeopleInDatabase = await pO.GetAllPeople(); PersonViewModel currentPerson = currentPeopleInDatabase.Find(x => x.Email.Equals(email)); List <HighScoreViewModel> currentHighscores = GetAllHighscores(); HighScoreViewModel inDatabase = currentHighscores.Find(x => x.PersonId.Equals(currentPerson.PersonId)); if (inDatabase == null || inDatabase.PersonId == Guid.Empty) { var result = await CreateHighscore(currentPerson.PersonId, email, newHighscoreDecimal); return(result); } else if (inDatabase.Email == email) { var result = await _highScoreOrchestrator.UpdateHighscore(new HighScoreViewModel { HighscoreId = inDatabase.HighscoreId, PersonId = inDatabase.PersonId, Email = email, Score = newHighscoreDecimal, DateAttained = DateTime.Now }); return(result); } else { var result = await CreateHighscore(inDatabase.PersonId, email, newHighscoreDecimal); return(result); } }
public void AddToDataBase(HighScoreViewModel ItemToAdd) { TestData.Add(ItemToAdd); }
public HighScorePage() { InitializeComponent(); DataContext = new HighScoreViewModel(); }
public void integrationTest_UpdateLeaderboard_ReturnsTrue() { // Create a controller to use methods from. This controller simulates what the database would do if given the commands. var controller = _mocker.Create <HighscoreService>(); // Create data. var HSList = controller.CreateDataSix(); // Find the person. var person4 = HSList.Find(x => x.PersonId == Guid.Parse("218d58cd-ecfc-43dd-b844-934f701af254")); // Update the highscore and set the result of the update to a var. // We have to also pass a previous model because we cannot create that functionality in these tests where in a database we could. var resultOfUpdate = controller.UpdateHighscore(Guid.Parse("218d58cd-ecfc-43dd-b844-934f701af254"), 700.00m, person4); // Expected result from the update. var expectedResultOfUpdate = "Succesfully Updated."; // Check if the right result was found. Assert.AreEqual(expectedResultOfUpdate, resultOfUpdate); // Get the index of the previous person var indexChanged = HSList.IndexOf(person4); // Actually hard update it in the list (Database would do this). HSList[indexChanged] = new HighScoreViewModel { PersonId = Guid.Parse("218d58cd-ecfc-43dd-b844-934f701af254"), Score = 700.00m, DateAttained = DateTime.Now }; // Resort the list. HSList = controller.SortHighscores(HSList); // Get all the people to verify their index number. var person1 = HSList.Find(x => x.PersonId == Guid.Parse("52fc5dd8-c147-4fbc-82e6-465fd09b01a3")); var person2 = HSList.Find(x => x.PersonId == Guid.Parse("2dfafb6c-6ce3-44e2-b41d-6bffcad912a9")); var person3 = HSList.Find(x => x.PersonId == Guid.Parse("218d48cd-ecfc-43dd-b844-934f701af254")); var person4Updated = HSList.Find(x => x.PersonId == Guid.Parse("218d58cd-ecfc-43dd-b844-934f701af254")); var person5 = HSList.Find(x => x.PersonId == Guid.Parse("218d68cd-ecfc-43dd-b844-934f701af254")); var person6 = HSList.Find(x => x.PersonId == Guid.Parse("218d78cd-ecfc-43dd-b844-934f701af254")); // Assert that all the highscores are correctly sorted. int indexCorrect1 = HSList.IndexOf(person1); Assert.AreEqual(0, indexCorrect1); int indexCorrect2 = HSList.IndexOf(person2); Assert.AreEqual(2, indexCorrect2); int indexCorrect3 = HSList.IndexOf(person3); Assert.AreEqual(4, indexCorrect3); int indexCorrect4 = HSList.IndexOf(person4Updated); Assert.AreEqual(1, indexCorrect4); int indexCorrect5 = HSList.IndexOf(person5); Assert.AreEqual(5, indexCorrect5); int indexCorrect6 = HSList.IndexOf(person6); Assert.AreEqual(3, indexCorrect6); }
public int CreateHighScore(HighScoreViewModel newHighScore) { // Mocking creation of high score method, method returns SaveChangesAsync(); which returns an int of objects saved. // Mocking one object each, so result is int = 1 returned return(1); }
private void LoadRelationshipProperties(HighScoreViewModel model) { var quizItem = _quizItemRepository.Get(model.QuizItemId); model.QuizItemName = quizItem.Name; }
// Original method returns -1 for error, 0 for no update, and 1 for successfully updated // Assuming success so returning 1 public int UpdateHighScore(HighScoreViewModel updateHighScore) { return(1); }