public Guid AgregarEncuentro(Encuentro encuentro) { if (DatosInvalidosEncuentro(encuentro)) { throw new EncuentroDataException(); } Deporte deporte = _deportesRepository.ObtenerDeportePorNombre(encuentro.Deporte.Nombre); if (deporte == null) { throw new NoExisteDeporteException(); } Equipo equipoLocal = _equiposRepository.ObtenerEquipoPorDeporte(encuentro.Deporte.Nombre, encuentro.EquipoLocal.Nombre); Equipo equipoVisitante = _equiposRepository.ObtenerEquipoPorDeporte(encuentro.Deporte.Nombre, encuentro.EquipoVisitante.Nombre); if (equipoLocal == null || equipoVisitante == null) { throw new NoExisteEquipoException(); } if (_encuentrosRepository.ExisteEncuentroEnFecha(encuentro.FechaHora, equipoLocal.Id) || _encuentrosRepository.ExisteEncuentroEnFecha(encuentro.FechaHora, equipoVisitante.Id)) { throw new ExisteEncuentroEnFecha(); } encuentro.EquipoLocal.Id = equipoLocal.Id; encuentro.EquipoVisitante.Id = equipoVisitante.Id; encuentro.Deporte.Id = deporte.Id; _encuentrosRepository.Insert(encuentro); _unitOfWork.Save(); return(encuentro.Id); }
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); }
public void AgregarDeporte(Deporte deporte) { if (!CampoValido(deporte.Nombre)) { throw new DeporteDataException(); } if (_deportesRepository.ObtenerDeportePorNombre(deporte.Nombre) != null) { throw new ExisteDeporteException(); } _deportesRepository.Insert(deporte); _unitOfWork.Save(); }
public Guid AgregarEquipo(Equipo equipo) { if (!CampoValido(equipo.Nombre) || !CampoValido(equipo.Deporte.Nombre)) throw new EquipoDataExceptiom(); Deporte deporte = _deportesRepository.ObtenerDeportePorNombre(equipo.Deporte.Nombre); if (deporte == null) throw new NoExisteDeporteException(); if (_equiposRepository.ObtenerEquipoPorDeporte(equipo.Deporte.Nombre, equipo.Nombre) !=null) throw new ExisteEquipoException(); if (equipo.Foto != null) { try { Convert.FromBase64String(equipo.Foto); } catch (FormatException e) { throw e; } } equipo.Deporte.Id = deporte.Id; _equiposRepository.Insert(equipo); _unitOfWork.Save(); return equipo.Id; }
public Guid AgregarParticipante(Participante participante) { if (!CampoValido(participante.Nombre) || !CampoValido(participante.Deporte.Nombre)) { throw new ParticipanteDataException(); } Deporte deporte = _deportesRepository.ObtenerDeportePorNombre(participante.Deporte.Nombre); if (deporte == null) { throw new NoExisteDeporteException(); } if (_participantesRepository.ObtenerParticipantePorDeporte(participante.Deporte.Nombre, participante.Nombre) != null) { throw new ExisteParticipanteException(); } if (participante.Foto != null) { try { string[] pd = participante.Foto.Split(','); Convert.FromBase64String(pd[1]); } catch (FormatException e) { throw e; } } participante.Deporte.Id = deporte.Id; _participantesRepository.Insert(participante); _unitOfWork.Save(); return(participante.Id); }