Beispiel #1
0
        // GET: api/Fechas/5
        //fpaz: trae la info de la fecha y todos sus partidos (sin el detalle del partido)
        public IHttpActionResult GetFecha(int id)
        {
            try
            {
                Fecha fecha = (from f in db.Fechas
                               where f.Id == id
                               select f)
                              .Include(p => p.Partidos)
                              .Include(a => a.Partidos.Select(ar => ar.Arbitro))
                              .FirstOrDefault();

                if (fecha == null)
                {
                    return(NotFound());
                }
                else
                {
                    InfoFecha infoFecha = new InfoFecha //instancio la clase auxiliar para mostrar la info de los partidos de la fecha
                    {
                        Id       = fecha.Id,
                        NumFecha = fecha.NumFecha,
                        torneoId = fecha.torneoId
                    };

                    List <InfoPartidoFixtureFecha> partidos = new List <InfoPartidoFixtureFecha>();

                    foreach (var item in fecha.Partidos)
                    {
                        InfoPartidoFixtureFecha p = new InfoPartidoFixtureFecha
                        {
                            Id   = item.Id,
                            Dia  = item.Dia,
                            Hora = item.Hora,
                            //Sede = item.Sede,
                            Sede                  = db.Sedes.Find(item.SedeId).Nombre,
                            GolesLocal            = item.GolesLocal,
                            GolesVisitante        = item.GolesVisitante,
                            nombreEquipoLocal     = db.Equipoes.Find(item.EquipoLocalId).Nombre,
                            nombreEquipoVisitante = db.Equipoes.Find(item.EquipoVisitanteId).Nombre,
                            nombreArbitro         = (from a in db.Arbitroes
                                                     where a.Id == item.ArbitroId
                                                     select a.NombreApellido).FirstOrDefault()
                        };

                        partidos.Add(p);
                    }

                    infoFecha.InfoPartidos = partidos;

                    return(Ok(infoFecha));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Beispiel #2
0
        // GET: api/Fechas/5
        //fpaz: trae la info de la fecha y todos sus partidos (sin el detalle del partido)
        public IHttpActionResult GetFecha(int id)
        {
            try
            {
                Fecha fecha = (from f in db.Fechas
                               where f.Id == id
                               select f)
                               .Include(p => p.Partidos)
                               .Include(a => a.Partidos.Select(ar => ar.Arbitro))
                               .FirstOrDefault();

                if (fecha == null)
                {
                    return NotFound();
                }
                else
                {
                    InfoFecha infoFecha = new InfoFecha //instancio la clase auxiliar para mostrar la info de los partidos de la fecha
                    {
                        Id = fecha.Id,
                        NumFecha = fecha.NumFecha,
                        torneoId = fecha.torneoId
                    };

                    List<InfoPartidoFixtureFecha> partidos = new List<InfoPartidoFixtureFecha>();

                    foreach (var item in fecha.Partidos)
                    {
                        InfoPartidoFixtureFecha p = new InfoPartidoFixtureFecha
                        {
                            Id = item.Id,
                            Dia = item.Dia,
                            Hora = item.Hora,
                            //Sede = item.Sede,
                            Sede= db.Sedes.Find(item.SedeId).Nombre,
                            GolesLocal = item.GolesLocal,
                            GolesVisitante = item.GolesVisitante,
                            nombreEquipoLocal = db.Equipoes.Find(item.EquipoLocalId).Nombre,
                            nombreEquipoVisitante = db.Equipoes.Find(item.EquipoVisitanteId).Nombre,
                            nombreArbitro = (from a in db.Arbitroes
                                             where a.Id == item.ArbitroId
                                             select a.NombreApellido).FirstOrDefault()
                        };

                        partidos.Add(p);
                    }

                    infoFecha.InfoPartidos = partidos;

                    return Ok(infoFecha);
                }


            }
            catch (Exception ex)
            {
                return BadRequest(ex.Message);
            }
        }