public ActionResult Snake(int skor2) { //try //{ AppUser kullanici = Session["girisyapan"] as AppUser; if (asRep.Any(x => x.AppUserID == kullanici.ID && x.Game == "Snake") == true) { AppUserScore varOlanKullaniciScore = asRep.Default(x => x.AppUserID == kullanici.ID && x.Game == "Snake"); Score skor = sRep.Default(x => x.ID == varOlanKullaniciScore.ScoreID); if (skor2 > skor.ScoreValue) { skor.ScoreValue = skor2; sRep.Update(skor); } else { ViewBag.gec = "Daha önceki skorunuzu geçemediniz. Oyun kaydedilmedi."; } } else { AppUserScore kullaniciScore = new AppUserScore(); kullaniciScore.AppUserID = kullanici.ID; Score score = new Score(); score.ScoreValue = skor2; sRep.Add(score); kullaniciScore.ScoreID = score.ID; kullaniciScore.Game = "Snake"; asRep.Add(kullaniciScore); } return(Json(new { result = 1, puan = skor2 })); //} //catch (Exception) //{ // return Json(new { result = 0 }); //} }
private void AddScore(int gameId, string userId, int drinks) { Score score = scoreRepo.getByGameAndUser(gameId, userId); if (score == null) { scoreRepo.Add(new Score() { gameId = gameId, userId = userId, score1 = drinks }); } else { score.score1 += drinks; scoreRepo.Update(score); } scoreRepo.Save(); }