コード例 #1
0
        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;
        }
コード例 #2
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();
            }

            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);
        }