Esempio n. 1
0
        public void AddFootballPlayerToTeam(FootballTeamPlayerViewModel model)
        {
            if (!UnitOfWork.FootballTeams.Any(x => x.Id == model.TeamId))
            {
                throw new ArgumentNullException("Not found in database!");
            }

            if (!UnitOfWork.FootballPlayers.Any(x => x.Id == model.PlayerId))
            {
                throw new ArgumentNullException("Not found in database!");
            }

            if (UnitOfWork.FootballTeamsPlayers.Any(
                    x => x.PlayerId == model.PlayerId &&
                    x.TeamId == model.TeamId &&
                    x.EndDate == null))
            {
                throw new ArgumentNullException("The player is already in the team!");
            }

            FootballTeamPlayer teamPlayerItem = AutoMapper.Mapper.Map <FootballTeamPlayer>(model);

            teamPlayerItem.CDate = DateTime.Now;

            UnitOfWork.FootballTeamsPlayers.Add(teamPlayerItem);
            UnitOfWork.SaveChanges();
        }
Esempio n. 2
0
        public void DeleteFootballPlayerFromTeam(int footballTeamPlayerId)
        {
            FootballTeamPlayer teamPlayerItem = UnitOfWork.FootballTeamsPlayers.FirstOrDefault(x => x.Id == footballTeamPlayerId);

            if (teamPlayerItem == null)
            {
                throw new ArgumentNullException("Not found in database!");
            }

            UnitOfWork.FootballTeamsPlayers.Remove(teamPlayerItem);
            UnitOfWork.SaveChanges();
        }
Esempio n. 3
0
        public void UpdateFootballTeamPlayer(FootballTeamPlayerViewModel model)
        {
            FootballTeamPlayer footballTeamPlayer = UnitOfWork.FootballTeamsPlayers.FirstOrDefault(x => x.Id == model.Id);

            if (footballTeamPlayer == null)
            {
                throw new ArgumentNullException("There is no such item in database");
            }

            footballTeamPlayer.StartDate      = model.StartDate;
            footballTeamPlayer.EndDate        = model.EndDate;
            footballTeamPlayer.PlayerStatusId = model.PlayerStatusId;
            footballTeamPlayer.CDate          = DateTime.Now;

            UnitOfWork.SaveChanges();
        }