Exemple #1
0
        public ActionResult Create([Bind(Include = "Game,PlayerID,CoachID,PlateAppearances,Singles,Doubles,Triples,HRs,Walks,HBP,Scrifices,OnByFeildersChoice,TotalBases,OnByInterference,DroppedThirdStrike,StolenBases,StolenBaseAttempts,SO,OtherBattingOuts,RBIs,RunsScored")] SubmitOffense subOffense, OffenseStats offenseStats, TotalOffense totalOff)
        {
            if (ModelState.IsValid)
            {
                string user           = User.Identity.GetUserId();
                var    coachRow       = from row in db.Coaches where row.UserId == user select row;
                var    coachRowResult = coachRow.FirstOrDefault();
                subOffense.CoachID = coachRowResult.CoachID;
                TotalOffensesController total = new TotalOffensesController();
                MorphingTables          morph = new MorphingTables();
                OffenseStatsController  off   = new OffenseStatsController();
                db.SubmitOffenses.Add(subOffense);
                db.SaveChanges();
                foreach (var item in db.GameOffenses)
                {
                    if (item.PlayerID == subOffense.PlayerID)
                    {
                        total.Edit(subOffense.PlayerID, subOffense.CoachID, subOffense.PlateAppearances, subOffense.Singles, subOffense.Doubles, subOffense.Triples, subOffense.HRs, subOffense.Walks, subOffense.HBP, subOffense.Scrifices, subOffense.OnByFeildersChoice, subOffense.TotalBases, subOffense.OnByInterference, subOffense.DroppedThirdStrike, subOffense.StolenBases, subOffense.StolenBaseAttempts, subOffense.SO, subOffense.OtherBattingOuts, subOffense.RBIs, subOffense.RunsScored);
                        return(RedirectToAction("Home", "Coaches"));
                    }
                }

                total.Create(subOffense.PlayerID, subOffense.CoachID, subOffense.PlateAppearances, subOffense.Singles, subOffense.Doubles, subOffense.Triples, subOffense.HRs, subOffense.Walks, subOffense.HBP, subOffense.Scrifices, subOffense.OnByFeildersChoice, subOffense.TotalBases, subOffense.OnByInterference, subOffense.DroppedThirdStrike, subOffense.StolenBases, subOffense.StolenBaseAttempts, subOffense.SO, subOffense.OtherBattingOuts, subOffense.RBIs, subOffense.RunsScored, totalOff);
                off.Create(totalOff.PlayerID, totalOff.CoachID, totalOff.PlateAppearances, totalOff.Singles, totalOff.Doubles, totalOff.Triples, totalOff.HRs, totalOff.Walks, totalOff.HBP, totalOff.Scrifices, totalOff.OnByFeildersChoice, totalOff.TotalBases, totalOff.OnByInterference, totalOff.DroppedThirdStrike, totalOff.StolenBases, totalOff.StolenBaseAttempts, totalOff.SO, totalOff.OtherBattingOuts, totalOff.RBIs, totalOff.RunsScored);
                return(RedirectToAction("Home", "Coaches"));
            }

            ViewBag.PlayerID = new SelectList(db.Players, "PlayerID", "FirstName", subOffense.PlayerID);
            return(View(subOffense));
        }
        // GET: GameOffenses/Edit/5
        public ActionResult Edit(int PlayerID, int CoachID, int PlateAppearances, int Singles, int Doubles, int Triples, int HRs, int Walks, int HBP, int Scrifices, int OnByFeildersChoice, int TotalBases, int OnByInterference, int DroppedThirdStrike, int StolenBases, int StolenBaseAttempts, int SO, int OtherBattingOuts, int RBIs, int RunsScored)
        {
            //if (id == null)
            //{
            //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            //}
            //TotalOffense gameOffense = db.GameOffenses.Find(id);
            //if (gameOffense == null)
            //{
            //    return HttpNotFound();
            //}
            MorphingTables morph        = new MorphingTables();
            var            result       = from row in db.GameOffenses where row.PlayerID == PlayerID select row;
            var            resultToUser = result.FirstOrDefault();

            resultToUser.CoachID          = CoachID;
            resultToUser.PlayerID         = PlayerID;
            resultToUser.PlateAppearances = morph.AddingStats(PlateAppearances, resultToUser.PlateAppearances);
            resultToUser.Singles          = morph.AddingStats(Singles, resultToUser.Singles);
            resultToUser.Doubles          = morph.AddingStats(Doubles, resultToUser.Doubles);
            resultToUser.Triples          = morph.AddingStats(Triples, resultToUser.Triples);
            resultToUser.HRs                = morph.AddingStats(HRs, resultToUser.HRs);
            resultToUser.Walks              = morph.AddingStats(Walks, resultToUser.Walks);
            resultToUser.HBP                = morph.AddingStats(HBP, resultToUser.HBP);
            resultToUser.Scrifices          = morph.AddingStats(Scrifices, resultToUser.Scrifices);
            resultToUser.OnByFeildersChoice = morph.AddingStats(OnByFeildersChoice, resultToUser.OnByFeildersChoice);
            resultToUser.TotalBases         = morph.AddingStats(TotalBases, resultToUser.TotalBases);
            resultToUser.OnByInterference   = morph.AddingStats(OnByInterference, resultToUser.OnByInterference);
            resultToUser.DroppedThirdStrike = morph.AddingStats(DroppedThirdStrike, resultToUser.DroppedThirdStrike);
            resultToUser.StolenBases        = morph.AddingStats(StolenBases, resultToUser.StolenBases);
            resultToUser.StolenBaseAttempts = morph.AddingStats(StolenBaseAttempts, resultToUser.StolenBaseAttempts);
            resultToUser.SO = morph.AddingStats(SO, resultToUser.SO);
            resultToUser.OtherBattingOuts = morph.AddingStats(OtherBattingOuts, resultToUser.OtherBattingOuts);
            resultToUser.RBIs             = morph.AddingStats(RBIs, resultToUser.RBIs);
            resultToUser.RunsScored       = morph.AddingStats(RunsScored, resultToUser.RunsScored);
            db.Entry(resultToUser).State  = EntityState.Modified;
            db.SaveChanges();
            OffenseStatsController newStats = new OffenseStatsController();

            newStats.Edit(resultToUser.PlayerID, resultToUser.CoachID, resultToUser.PlateAppearances, resultToUser.Singles, resultToUser.Doubles, resultToUser.Triples, resultToUser.HRs, resultToUser.Walks, resultToUser.HBP, resultToUser.Scrifices, resultToUser.OnByFeildersChoice, resultToUser.TotalBases, resultToUser.OnByInterference, resultToUser.DroppedThirdStrike, resultToUser.StolenBases, resultToUser.StolenBaseAttempts, resultToUser.SO, resultToUser.OtherBattingOuts, resultToUser.RBIs, resultToUser.RunsScored);
            return(View());
        }