public Team Add(CreateTeamDto teamToCreate) { var players = teamToCreate.Roster.Select(x => x.Id); var roster = _unitOfWork.Context.Players .Where(p => players.Contains(p.Id)).ToList(); var newTeam = new TeamEntity { Name = teamToCreate.Name, Coach = teamToCreate.Coach, CaptainId = teamToCreate.Captain.Id, Achievements = teamToCreate.Achievements, Players = roster }; if (!_dbStorageSpecification.IsSatisfiedBy(newTeam)) { throw new InvalidEntityException(); } _dalTeams.Add(newTeam); _unitOfWork.Commit(); return(new Team( newTeam.Id, newTeam.Name, newTeam.Coach, newTeam.Achievements, new PlayerId(newTeam.CaptainId), teamToCreate.Roster.ToList() )); }
/// <summary> /// Adds new player. /// </summary> /// <param name="playerDto">The player for adding.</param> public Player Add(CreatePlayerDto playerDto) { var newEntity = new PlayerEntity { FirstName = playerDto.FirstName, LastName = playerDto.LastName, BirthYear = playerDto.BirthYear, Height = playerDto.Height, Weight = playerDto.Weight }; if (!_dbStorageSpecification.IsSatisfiedBy(newEntity)) { throw new InvalidEntityException(); } _dalPlayers.Add(newEntity); _unitOfWork.Commit(); return(new Player(newEntity.Id, newEntity.FirstName, newEntity.LastName) { BirthYear = newEntity.BirthYear, Height = newEntity.Height, Weight = newEntity.Weight }); }
/// <summary> /// Adds new game. /// </summary> /// <param name="newEntity">Game to add.</param> public void Add(Game newEntity) { var newGame = new GameResultEntity(); DomainToDal.Map(newGame, newEntity); _dalGame.Add(newGame); _unitOfWork.Commit(); newEntity.Id = newGame.Id; }
/// <summary> /// Adds new game. /// </summary> /// <param name="newRequest">Request to add.</param> public void Add(Request newRequest) { var newRequestEntity = new RequestEntity(); DomainToDal.Map(newRequestEntity, newRequest); _dalRequest.Add(newRequestEntity); _unitOfWork.Commit(); newRequest.Id = newRequestEntity.Id; }
/// <summary> /// Adds new user. /// </summary> /// <param name="newEntity">The user for adding.</param> public void Add(User newEntity) { var newUser = new UserEntity(); DomainToDal.Map(newUser, newEntity); _unitOfWork.Context.Users.Add(newUser); _unitOfWork.Commit(); newEntity.Id = newUser.Id; }
/// <summary> /// Adds new feedback. /// </summary> /// <param name="newEntity">The feedback for adding.</param> public void Add(Feedback newEntity) { var newFeedback = new FeedbackEntity(); DomainToDal.Map(newFeedback, newEntity); if (!_dbStorageSpecification.IsSatisfiedBy(newFeedback)) { throw new InvalidEntityException(); } _dalFeedbacks.Add(newFeedback); _unitOfWork.Commit(); newEntity.Id = newFeedback.Id; }
/// <summary> /// Adds new tournament. /// </summary> /// <param name="newEntity">The tournament for adding.</param> public void Add(Tournament newEntity) { var tournament = new TournamentEntity(); DomainToDal.Map(tournament, newEntity); if (!_dbStorageSpecification.IsSatisfiedBy(tournament)) { throw new InvalidEntityException(); } _dalTournaments.Add(tournament); _unitOfWork.Commit(); MapIdentifiers(newEntity, tournament); }
/// <summary> /// Adds new player. /// </summary> /// <param name="newEntity">The player for adding.</param> public void Add(Player newEntity) { var newPlayer = new PlayerEntity(); DomainToDal.Map(newPlayer, newEntity); if (!_dbStorageSpecification.IsSatisfiedBy(newPlayer)) { throw new InvalidEntityException(); } _dalPlayers.Add(newPlayer); _unitOfWork.Commit(); newEntity.Id = newPlayer.Id; }
/// <summary> /// Adds new team. /// </summary> /// <param name="newEntity">The team for adding.</param> public void Add(Team newEntity) { var newTeam = new TeamEntity(); DomainToDal.Map(newTeam, newEntity); if (!_dbStorageSpecification.IsSatisfiedBy(newTeam)) { throw new InvalidEntityException(); } _dalTeams.Add(newTeam); _unitOfWork.Commit(); newEntity.Id = newTeam.Id; }