public ActionResult DeleteConfirmed(int id)
        {
            TournamentScore tournamentScore = db.TournamentScores.Find(id);

            db.TournamentScores.Remove(tournamentScore);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "TournamentScoresID,TournamentID,PlayerID,PointsFor,PointsAgainst,LeagueID,DefenseAgainst")] TournamentScore tournamentScore)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tournamentScore).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Details", "MainTournaments", new { id = tournamentScore.TournamentID }));
     }
     ViewBag.LeagueID     = new SelectList(db.Leagues, "LeagueID", "LeagueName", tournamentScore.LeagueID);
     ViewBag.PlayerID     = new SelectList(db.Players, "PlayerID", "PlayerName", tournamentScore.PlayerID);
     ViewBag.TournamentID = new SelectList(db.Tournaments, "TournamentID", "TournamentName", tournamentScore.TournamentID);
     return(View(tournamentScore));
 }
        public ActionResult Create([Bind(Include = "TournamentScoresID,TournamentID,PlayerID,PointsFor,PointsAgainst,LeagueID,DefenseAgainst")] TournamentScore tournamentScore)
        {
            if (ModelState.IsValid)
            {
                db.TournamentScores.Add(tournamentScore);
                db.SaveChanges();
                return(RedirectToAction("Index", "MainTournaments"));
            }

            ViewBag.LeagueID     = new SelectList(db.Leagues, "LeagueID", "LeagueName", tournamentScore.LeagueID);
            ViewBag.PlayerID     = new SelectList(db.Players, "PlayerID", "PlayerName", tournamentScore.PlayerID);
            ViewBag.TournamentID = new SelectList(db.Tournaments, "TournamentID", "TournamentName", tournamentScore.TournamentID);
            return(View(tournamentScore));
        }
        // GET: MainTournamentScores/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TournamentScore tournamentScore = db.TournamentScores.Find(id);

            if (tournamentScore == null)
            {
                return(HttpNotFound());
            }
            return(View(tournamentScore));
        }
        // GET: MainTournamentScores/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TournamentScore tournamentScore = db.TournamentScores.Find(id);

            if (tournamentScore == null)
            {
                return(HttpNotFound());
            }
            ViewBag.LeagueID     = new SelectList(db.Leagues, "LeagueID", "LeagueName", tournamentScore.LeagueID);
            ViewBag.PlayerID     = new SelectList(db.Players, "PlayerID", "PlayerName", tournamentScore.PlayerID);
            ViewBag.TournamentID = new SelectList(db.Tournaments, "TournamentID", "TournamentName", tournamentScore.TournamentID);
            return(View(tournamentScore));
        }
        public ActionResult Upload(HttpPostedFileBase postedFile)
        {
            if (postedFile != null)
            {
                ExcelPackage   package   = new ExcelPackage(postedFile.InputStream);
                ExcelWorksheet worksheet = package.Workbook.Worksheets.FirstOrDefault();

                TournamentScore tournamentScore = new TournamentScore();

                int rowLength = worksheet.Dimension.End.Row;

                // plus 1 to avoid headers
                for (int rowIndex = worksheet.Dimension.Start.Row + 1; rowIndex <= rowLength; rowIndex++)
                {
                    var playerId = worksheet.Cells[rowIndex, 3].Value;
                    // don't include benched players or rows without a playerID
                    if (worksheet.Cells[rowIndex, 9].GetValue <int>() != 1 && playerId != null)
                    {
                        tournamentScore.TournamentID   = worksheet.Cells[rowIndex, 1].GetValue <int>();
                        tournamentScore.LeagueID       = worksheet.Cells[rowIndex, 2].GetValue <int>();
                        tournamentScore.PlayerID       = worksheet.Cells[rowIndex, 3].GetValue <int>();
                        tournamentScore.PointsFor      = worksheet.Cells[rowIndex, 5].GetValue <int>();
                        tournamentScore.PointsAgainst  = worksheet.Cells[rowIndex, 6].GetValue <int>();
                        tournamentScore.MissedDrives   = worksheet.Cells[rowIndex, 8].GetValue <bool>();
                        tournamentScore.DefenseAgainst = worksheet.Cells[rowIndex, 7].GetValue <int>();

                        db.TournamentScores.Add(tournamentScore);
                        db.SaveChanges();
                    }
                }

                //ViewBag.Message = "File uploaded successfully.";
            }

            return(View());
        }