Пример #1
0
 public ActionResult Edit([Bind(Include = "teamID,teamName")] Team team)
 {
     if (ModelState.IsValid)
     {
         db.Entry(team).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(team));
 }
Пример #2
0
        public ActionResult Create([Bind(Include = "teamID,teamName")] Team team)
        {
            if (ModelState.IsValid)
            {
                db.Teams.Add(team);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(team));
        }
Пример #3
0
        public ActionResult Create([Bind(Include = "positionCode,positionDescription")] Position position)
        {
            if (ModelState.IsValid)
            {
                db.Positions.Add(position);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(position));
        }
Пример #4
0
        public ActionResult Create([Bind(Include = "playerID,playerLastName,playerFirstName,positionCode,teamID")] Player player)
        {
            if (ModelState.IsValid)
            {
                db.Players.Add(player);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.positionCode = new SelectList(db.Positions, "positionCode", "positionDescription", player.positionCode);
            ViewBag.teamID       = new SelectList(db.Teams, "teamID", "teamName", player.teamID);
            return(View(player));
        }
Пример #5
0
        public async Task <IActionResult> DeleteTeam(int id)
        {
            var team = await _db.Teams.FindAsync(id);

            var faTeam = await _db.Teams.FirstOrDefaultAsync(team => team.TeamName == "Free Agents");

            List <Player> model = _db.Players
                                  .Where(player => player.Team == team.TeamName).ToList();

            foreach (Player player in model)
            {
                player.Team = faTeam.TeamName;
                faTeam.Players.Add(player);
                _db.SaveChanges();
            }

            if (team == null)
            {
                return(NotFound());
            }

            _db.Teams.Remove(team);
            await _db.SaveChangesAsync();

            return(NoContent());
        }
        public static void PrepareContext()
        {
            var options = new DbContextOptionsBuilder <NBAContext>().UseInMemoryDatabase(databaseName: "nbaDB").Options;

            _context = new NBAContext(options);

            PreparePlayers();

            _context.SaveChanges();
        }
Пример #7
0
 public void SaveChanges()
 {
     _context.SaveChanges();
 }