예제 #1
0
        public bool FixtureGenerado(DateTime fechaInicio, string deporte, string tipo)
        {
            if (!CampoValido(deporte) || !CampoValido(tipo) || (tipo != "Liga" && tipo != "Grupos"))
            {
                throw new EncuentroDataException();
            }
            Deporte deporteActual = _deportesRepository.ObtenerDeportePorNombre(deporte);

            if (deporteActual == null)
            {
                throw new NoExisteDeporteException();
            }
            List <Equipo> equipos = _equiposRepository.ObtenerEquiposPorDeporte(deporte);

            if (equipos == null || equipos.Count == 1)
            {
                throw new NoExistenEquiposException();
            }
            Fixture          fixture    = GenerarFixture(fechaInicio, tipo, equipos);
            List <Encuentro> encuentros = fixture.GenerarFixture();
            bool             generado   = true;

            foreach (Encuentro encuentro in encuentros)
            {
                if (ExisteEncuentroEquipo(encuentro.FechaHora, equipos))
                {
                    generado = false;
                }
                break;
            }
            if (generado)
            {
                foreach (Encuentro encuentro in encuentros)
                {
                    encuentro.Deporte = deporteActual;
                    _encuentrosRepository.Insert(encuentro);
                    _unitOfWork.Save();
                }
            }
            return(generado);
        }
 public IEnumerable<Equipo> ObtenerEquiposPorDeporte(string deporte)
 {
     return _equiposRepository.ObtenerEquiposPorDeporte(deporte);
 }