// GET: PitchStats/Edit/5 public void Edit(int PlayerID, int CoachId, int OpponentOfficialAtBats, int OpponentHits, int EarnedRunsScored, int InningsPitched, int StrikeOuts, int HomeRuns, int Walks, int BattersHBP, int PickOffAttempts, int PickOffs) { //if (id == null) //{ // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //} //PitchStats pitchStats = db.PitchStats.Find(id); //if (pitchStats == null) //{ // return HttpNotFound(); //} //ViewBag.PlayerID = new SelectList(db.Players, "PlayerID", "FirstName", pitchStats.PlayerID); //return View(pitchStats); var result = from row in db.PitchStats where row.PlayerID == PlayerID select row; var resultToUser = result.FirstOrDefault(); PitchingHelpers helpers = new PitchingHelpers(); resultToUser.PlayerID = PlayerID; resultToUser.CoachID = CoachId; resultToUser.EarnedRunAvereage = helpers.ERAcalc(EarnedRunsScored, InningsPitched); resultToUser.OpponentBattingAverage = helpers.OpponentBA(OpponentHits, OpponentOfficialAtBats); resultToUser.WHIP = helpers.WHIP(Walks, OpponentHits, InningsPitched); resultToUser.StrikeOuts = StrikeOuts; resultToUser.StrikeOutPercentage = helpers.SimpleDivision(StrikeOuts, OpponentOfficialAtBats); resultToUser.PickOffPercentage = helpers.SimpleDivision(PickOffs, PickOffAttempts); resultToUser.WalksPerAtBat = helpers.SimpleDivision(OpponentOfficialAtBats, Walks); resultToUser.WalksPerAtBat = helpers.SimpleDivision(Walks, InningsPitched); db.Entry(resultToUser).State = EntityState.Modified; db.SaveChanges(); }
// GET: PitchStats/Create public void Create(int PlayerID, int CoachId, int OpponentOfficialAtBats, int OpponentHits, int EarnedRunsScored, int InningsPitched, int StrikeOuts, int HomeRuns, int Walks, int BattersHBP, int PickOffAttempts, int PickOffs) { PitchingHelpers helpers = new PitchingHelpers(); stats.PlayerID = PlayerID; stats.CoachID = CoachId; stats.EarnedRunAvereage = helpers.ERAcalc(EarnedRunsScored, InningsPitched); stats.OpponentBattingAverage = helpers.OpponentBA(OpponentHits, OpponentOfficialAtBats); stats.WHIP = helpers.WHIP(Walks, OpponentHits, InningsPitched); stats.StrikeOuts = StrikeOuts; stats.StrikeOutPercentage = helpers.SimpleDivision(StrikeOuts, OpponentOfficialAtBats); stats.PickOffPercentage = helpers.SimpleDivision(PickOffs, PickOffAttempts); stats.WalksPerAtBat = helpers.SimpleDivision(OpponentOfficialAtBats, Walks); stats.WalksPerAtBat = helpers.SimpleDivision(Walks, InningsPitched); db.PitchStats.Add(stats); db.SaveChanges(); }