Exemplo n.º 1
0
 public TeamDTO CreateTeam(TeamDTO team)
 {
     validator.ValidatePermissions();
     try
     {
         Team domainTeam = teamMapper.Map(team);
         teamRepository.Add(domainTeam);
         return(teamMapper.Map(domainTeam));
     }
     catch (DataAccessException e)
     {
         throw new ServicesException($"Failure to add team with name {team.Name}.", e);
     }
 }
Exemplo n.º 2
0
        public SportDTO CreateSport(SportDTO sportDTO)
        {
            validator.ValidatePermissions();
            Sport sport = sportMapper.Map(sportDTO);

            try
            {
                sportRepository.Add(sport);
                return(sportMapper.Map(sport));
            }
            catch (DataAccessException e)
            {
                throw new ServicesException($"Failure to create sport with name {sportDTO.Name}.", e);
            }
        }
Exemplo n.º 3
0
        public UserDTO CreateUser(UserDTO userDTO)
        {
            adminValidator.ValidatePermissions();
            User user = userMapper.Map(userDTO);

            try
            {
                userRepository.Add(user);
                return(userMapper.Map(user));
            }
            catch (DataAccessException e)
            {
                throw new ServicesException($"User with name {user.Name} already exists.", e);
            }
        }
Exemplo n.º 4
0
 public EncounterDTO CreateEncounter(EncounterDTO encounterDTO)
 {
     try
     {
         adminValidator.ValidatePermissions();
         Encounter encounter = mapper.Map(encounterDTO);
         ValidateNonOverlappingOfDates(encounter);
         encounterRepository.Add(encounter);
         return(mapper.Map(encounter));
     }
     catch (DataAccessException e)
     {
         throw new ServicesException(e.Message, e);
     }
     catch (DomainException e)
     {
         throw new ServicesException(e.Message, e);
     }
 }
Exemplo n.º 5
0
        public IEnumerable <EncounterDTO> CreateFixture(string fixtureGeneratorName, string sportName, DateTime startDate)
        {
            adminValidator.ValidatePermissions();
            ValidateSportIsTwoPlayerSport(sportName);
            IFixtureGenerator       generatorServices = GetFixtureGenerator(fixtureGeneratorName, sportName);
            IEnumerable <Team>      teamsInSport      = teamRepo.GetAll().Where(t => t.Sport.Name == sportName);
            ICollection <Encounter> encounters        = generatorServices.GenerateFixture(teamsInSport, startDate);

            ValidateFixture(encounters);
            SaveEncounters(encounters);
            return(encounters.Select(e => mapper.Map(e)));
        }
Exemplo n.º 6
0
        public IEnumerable <LogDTO> GetLogs(DateTime start, DateTime end)
        {
            validator.ValidatePermissions();
            List <LogDTO> logs = repo.GetAll().ToList();

            if (start != new DateTime())
            {
                logs.RemoveAll(l => l.DateTime < start);
            }
            if (end != new DateTime())
            {
                logs.RemoveAll(l => l.DateTime > end);
            }
            return(logs);
        }