public ActionResult Score(PlayerEventCountryScore model) { //check validity of user Guid currentplayer = (Guid)Membership.GetUser().ProviderUserKey; if (currentplayer != model.PlayerGuid) { //invalid user -- throw error throw new Exception("You are not the correct player for this record"); } //check validity of model try { if (ModelState.IsValid) { db.RecordPlayerScore(model); return(RedirectToAction("Play")); } else { throw new Exception("Modelstate.invalid"); } } catch (Exception ex) { ModelState.AddModelError("Error", ex); model.EventCountry = db.GetEventCountry(model.EventCountryID); return(View(model)); } }
public ActionResult Score(int id) { PlayerEventCountryScore model = db.GetPlayerScoreByID(id); Guid currentplayer = (Guid)Membership.GetUser().ProviderUserKey; if (currentplayer != model.PlayerGuid) { throw new Exception("You are not the correct player for this record"); } return(View(model)); }
void SourceRepository.RecordPlayerScore(PlayerEventCountryScore model) { if (model.Fattest) { foreach (var ps in db.PlayerScores.Where(x => x.PlayerGuid == model.PlayerGuid && x.Fattest == true)) { ps.Fattest = false; } } db.Entry(model).State = EntityState.Modified; db.SaveChanges(); }
public ActionResult Fattest(int id) { PlayerEventCountryScore pecs = db.GetPlayerScoreByID(id); //get current user Guid playerID = pecs.PlayerGuid; //get any fattest scores==true var FatScores = db.GetPlayerScoresForYear(pecs.EventCountry.Event.Year, playerID).Where(x => x.Fattest == true); if (FatScores.Count() > 0) { return(Json(new { success = true, matches = FatScores.Select(x => x.EventCountry.Country.Name) }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false }, JsonRequestBehavior.AllowGet)); } }