Ejemplo n.º 1
0
        /// <summary>
        /// Method "Delete" finds an existing trainer to which the given id matches and deletes him
        /// </summary>
        /// <param name="id"></param>
        public void Delete(int id)
        {
            using (sportsClubContext = new SportsClubContext(Connection))
            {
                var item = sportsClubContext.Trainers.Find(id);

                if (item != null)
                {
                    foreach (var team in sportsClubContext.Teams)
                    {
                        if (team.TrainerId == item.Id)
                        {
                            TeamBusiness teamBusiness = new TeamBusiness();
                            teamBusiness.Delete(team.Id);
                        }
                    }

                    try
                    {
                        sportsClubContext.Trainers.Remove(item);
                    }
                    catch
                    {
                        sportsClubContext.Trainers.Remove(item);
                    }
                    sportsClubContext.SaveChanges();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method "Add" adds a new trainer to the database
        /// </summary>
        /// <param name="trainer"></param>
        public void Add(Trainer trainer)
        {
            using (sportsClubContext = new SportsClubContext(Connection))
            {
                CheckIfTrainerNameIsCorrect(trainer);

                sportsClubContext.Trainers.Add(trainer);
                sportsClubContext.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Method "Add" adds a new sport to the database
        /// </summary>
        /// <param name="sport"></param>
        public void Add(Sport sport)
        {
            using (sportsClubContext = new SportsClubContext(Connection))
            {
                CheckIfSportExists(sport);
                CheckIfSportNameIsCorrect(sport);

                sportsClubContext.Sports.Add(sport);
                sportsClubContext.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Method "Add" adds a new game to the database
        /// </summary>
        /// <param name="game"></param>
        public void Add(Game game)
        {
            using (sportsClubContext = new SportsClubContext(Connection))
            {
                CheckIfTeamExists(game.FirstTeamId);
                CheckIfTeamExists(game.SecondTeamId);

                sportsClubContext.Games.Add(game);
                sportsClubContext.SaveChanges();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Method "Add" adds a new player to the database
        /// </summary>
        /// <param name="player"></param>
        public void Add(Player player)
        {
            using (sportsClubContext = new SportsClubContext(Connection))
            {
                CheckIfTeamExists(player.TeamId);
                CheckIfPlayerNameIsCorrect(player);

                sportsClubContext.Players.Add(player);
                sportsClubContext.SaveChanges();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Method "Add" adds a new team to the database
        /// </summary>
        /// <param name="team"></param>
        public void Add(Team team)
        {
            using (sportsClubContext = new SportsClubContext(Connection))
            {
                CheckIfSportExists(team.SportId);
                CheckIfTrainerExists(team.TrainerId);
                CheckIfTeamNameIsCorrect(team);
                CheckIfTeamExists(team);

                sportsClubContext.Teams.Add(team);
                sportsClubContext.SaveChanges();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Method "Update" finds an existing trainer and changes the information about him
        /// </summary>
        /// <param name="trainer"></param>
        public void Update(Trainer trainer)
        {
            using (sportsClubContext = new SportsClubContext(Connection))
            {
                var item = sportsClubContext.Trainers.Find(trainer.Id);

                if (item != null)
                {
                    CheckIfTrainerNameIsCorrect(trainer);

                    sportsClubContext.Entry(item).CurrentValues.SetValues(trainer);
                    sportsClubContext.SaveChanges();
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Method "Update" finds an existing sport and changes the information about it
        /// </summary>
        /// <param name="sport"></param>
        public void Update(Sport sport)
        {
            using (sportsClubContext = new SportsClubContext(Connection))
            {
                var item = sportsClubContext.Sports.Find(sport.Id);

                if (item != null)
                {
                    CheckIfSportExists(sport);
                    CheckIfSportNameIsCorrect(sport);

                    sportsClubContext.Entry(item).CurrentValues.SetValues(sport);
                    sportsClubContext.SaveChanges();
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Method "Update" finds an existing game and changes the information about it
        /// </summary>
        /// <param name="game"></param>
        public void Update(Game game)
        {
            using (sportsClubContext = new SportsClubContext(Connection))
            {
                var item = sportsClubContext.Games.Find(game.Id);

                if (item != null)
                {
                    CheckIfTeamExists(game.FirstTeamId);
                    CheckIfTeamExists(game.SecondTeamId);

                    sportsClubContext.Entry(item).CurrentValues.SetValues(game);
                    sportsClubContext.SaveChanges();
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Method "Update" finds an existing player and changes the information about him
        /// </summary>
        /// <param name="player"></param>
        public void Update(Player player)
        {
            using (sportsClubContext = new SportsClubContext(Connection))
            {
                var item = sportsClubContext.Players.Find(player.Id);

                if (item != null)
                {
                    CheckIfTeamExists(player.TeamId);
                    CheckIfPlayerNameIsCorrect(player);

                    sportsClubContext.Entry(item).CurrentValues.SetValues(player);
                    sportsClubContext.SaveChanges();
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Method "Update" finds an existing team and changes the information about it
        /// </summary>
        /// <param name="team"></param>
        public void Update(Team team)
        {
            using (sportsClubContext = new SportsClubContext(Connection))
            {
                var item = sportsClubContext.Teams.Find(team.Id);

                if (item != null)
                {
                    CheckIfSportExists(team.SportId);
                    CheckIfTrainerExists(team.TrainerId);
                    CheckIfTeamNameIsCorrect(team);
                    CheckIfTeamExists(team);

                    sportsClubContext.Entry(item).CurrentValues.SetValues(team);
                    sportsClubContext.SaveChanges();
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Method "Delete" finds an existing game to which the given id matches and deletes it
        /// </summary>
        /// <param name="id"></param>
        public void Delete(int id)
        {
            using (sportsClubContext = new SportsClubContext(Connection))
            {
                var item = sportsClubContext.Games.Find(id);

                if (item != null)
                {
                    try
                    {
                        sportsClubContext.Games.Remove(item);
                    }
                    catch
                    {
                        sportsClubContext.Games.Remove(item);
                    }
                    sportsClubContext.SaveChanges();
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Method "Delete" finds an existing team to which the given id matches and deletes it
        /// </summary>
        /// <param name="id"></param>
        public void Delete(int id)
        {
            using (sportsClubContext = new SportsClubContext(Connection))
            {
                var item = sportsClubContext.Teams.Find(id);

                if (item != null)
                {
                    foreach (var player in sportsClubContext.Players)
                    {
                        if (player.TeamId == item.Id)
                        {
                            sportsClubContext.Players.Remove(player);
                        }
                    }

                    foreach (var game in sportsClubContext.Games)
                    {
                        if (game.FirstTeamId == item.Id || game.SecondTeamId == item.Id)
                        {
                            sportsClubContext.Games.Remove(game);
                        }
                    }

                    try
                    {
                        sportsClubContext.Teams.Remove(item);
                    }
                    catch
                    {
                        sportsClubContext.Teams.Remove(item);
                    }
                    sportsClubContext.SaveChanges();
                }
            }
        }
Ejemplo n.º 14
0
 public int Save()
 {
     return(ctx.SaveChanges());;
 }