Beispiel #1
0
        public Guid AgregarEncuentro(Encuentro encuentro)
        {
            if (DatosInvalidosEncuentro(encuentro))
            {
                throw new EncuentroDataException();
            }
            Deporte deporte = _deportesRepository.ObtenerDeportePorNombre(encuentro.Deporte.Nombre);

            if (deporte == null)
            {
                throw new NoExisteDeporteException();
            }
            ICollection <ParticipanteEncuentro> Puntajes = encuentro.ParticipanteEncuentro;

            if (Puntajes == null)
            {
                throw new NoExisteParticipanteException();
            }
            if (Puntajes.Count == 0)
            {
                throw new NoExisteParticipanteException();
            }
            if (Puntajes.Count < 2)
            {
                throw new CantidadIncorrectaDePartcipantesException();
            }
            if (!deporte.EsIndividual && Puntajes.Count != 2)
            {
                throw new CantidadIncorrectaDePartcipantesException();
            }
            if (HayPartcipanteRepetido(Puntajes))
            {
                throw new ParticipantesRepetidoException();
            }
            if (ExisteEcuentroMismoDiaParaParticipantes(encuentro))
            {
                throw new ExisteEncuentroMismoDiaException();
            }
            if (!PuntajesCorrectos(encuentro, deporte))
            {
                throw new ResultadoIncorrectoException();
            }
            foreach (ParticipanteEncuentro p in Puntajes)
            {
                p.Participante = _participantesRepository.ObtenerParticipantePorId(p.ParticipanteId);
                if (!p.Participante.Deporte.Equals(deporte))
                {
                    throw new NoCoincideDeporteException();
                }
            }
            encuentro.ParticipanteEncuentro = Puntajes;
            encuentro.Deporte.Id            = deporte.Id;
            _encuentrosRepository.Insert(encuentro);
            _unitOfWork.Save();
            return(encuentro.Id);
        }
Beispiel #2
0
 public Participante ObtenerParticipantePorId(Guid id)
 {
     return(_participantesRepository.ObtenerParticipantePorId(id));
 }