Beispiel #1
0
        private void ValidarGoleadores(CargarGoleadoresVM vm)
        {
            if (vm.GoleadoresDelLocal != null && vm.CantidadDeGolesGoleadorLocal.Any(x => x < 1) ||
                vm.GoleadoresDelVisitante != null && vm.CantidadDeGolesGoleadorVisitante.Any(x => x < 1))
            {
                ModelState.AddModelError("", "La cantidad de goles no puede ser menor a uno.");
            }

            //if (vm.GoleadoresDelLocal != null && vm.GoleadoresDelLocal.GroupBy(x => x).Any(y => y.Count() > 1)
            //	|| vm.GoleadoresDelVisitante != null && vm.CantidadDeGolesGoleadorVisitante.GroupBy(x => x).Any(y => y.Count() > 1))
            //	ModelState.AddModelError("", "No puede haber jugadores repetidos.");
        }
Beispiel #2
0
        public ActionResult CargarGoleadores(CargarGoleadoresVM vm)
        {
            ValidarGoleadores(vm);
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("CargarGoleadores", new { id = vm.PartidoId }));
            }

            var model = Context.Partidos.Find(vm.PartidoId);

            var goleadores = Context.Goleadores.Where(x => x.PartidoId == model.Id);

            Context.Goleadores.RemoveRange(goleadores);

            VMM.MapForCargarGoleadores(vm, model);

            Context.SaveChanges();

            return(RedirectToAction("Details", new { id = model.Id }));
        }
Beispiel #3
0
        private static void MapGoleadores(IList <Goleador> model, CargarGoleadoresVM vm)
        {
            var goleadoresLocal     = model.Where(x => x.EquipoId == x.Partido.Jornada.LocalId).ToList();
            var goleadoresVisitante = model.Where(x => x.EquipoId == x.Partido.Jornada.VisitanteId).ToList();

            vm.GoleadoresDelLocal           = new int[goleadoresLocal.Count];
            vm.CantidadDeGolesGoleadorLocal = new int[goleadoresLocal.Count];
            for (var i = 0; i < goleadoresLocal.Count; i++)
            {
                vm.GoleadoresDelLocal[i]           = goleadoresLocal[i].JugadorId;
                vm.CantidadDeGolesGoleadorLocal[i] = goleadoresLocal[i].Cantidad;
            }

            vm.GoleadoresDelVisitante           = new int[goleadoresVisitante.Count];
            vm.CantidadDeGolesGoleadorVisitante = new int[goleadoresVisitante.Count];
            for (var i = 0; i < goleadoresVisitante.Count; i++)
            {
                vm.GoleadoresDelVisitante[i]           = goleadoresVisitante[i].JugadorId;
                vm.CantidadDeGolesGoleadorVisitante[i] = goleadoresVisitante[i].Cantidad;
            }
        }
Beispiel #4
0
        public CargarGoleadoresVM MapForCargarGoleadores(IList <Goleador> goleadores, Partido partido)
        {
            var jugadoresDelLocal = partido.Jornada.Local.JugadorEquipo
                                    .OrderBy(x => x.Jugador.Categoria())
                                    .Select(x => new IdDescripcionVM
            {
                Id          = Convert.ToInt32(x.JugadorId),
                Descripcion = x.Jugador.Descripcion()
            })
                                    .ToList();

            var jugadoresDelVisitante = partido.Jornada.Visitante?.JugadorEquipo
                                        .OrderBy(x => x.Jugador.Categoria())
                                        .Select(x => new IdDescripcionVM
            {
                Id          = Convert.ToInt32(x.JugadorId),
                Descripcion = x.Jugador.Descripcion()
            })
                                        .ToList();

            var vm = new CargarGoleadoresVM
            {
                JornadaId                     = partido.JornadaId,
                PartidoId                     = partido.Id,
                CategoriaId                   = partido.Categoria.Id,
                Titulo                        = $"Cat: {partido.Categoria.Nombre} - {partido.Jornada.NombreDelLocal()}: {partido.GolesLocal} {partido.Jornada.NombreDelVisitante()}: {partido.GolesVisitante}",
                TotalDeGolesDelLocal          = ParseGoles(partido.GolesLocal),
                TotalDeGolesDelVisitante      = ParseGoles(partido.GolesVisitante),
                TodosLosJugadoresDelLocal     = JsonConvert.SerializeObject(jugadoresDelLocal),
                TodosLosJugadoresDelVisitante = JsonConvert.SerializeObject(jugadoresDelVisitante),
                EquipoLocalNombre             = partido.Jornada.NombreDelLocal(),
                EquipoVisitanteNombre         = partido.Jornada.NombreDelVisitante()
            };

            MapGoleadores(goleadores, vm);

            return(vm);
        }
Beispiel #5
0
        public void MapForCargarGoleadores(CargarGoleadoresVM vm, Partido model)
        {
            model.Goleadores = new List <Goleador>();

            if (vm.GoleadoresDelLocal != null)
            {
                for (var i = 0; i < vm.GoleadoresDelLocal.Length; i++)
                {
                    var jug      = Context.Jugadores.Find(vm.GoleadoresDelLocal[i]);
                    var goleador = new Goleador
                    {
                        JugadorId = jug.Id,
                        EquipoId  = model.Jornada.LocalIdInt(),
                        Cantidad  = vm.CantidadDeGolesGoleadorLocal[i],
                        PartidoId = model.Id
                    };
                    model.Goleadores.Add(goleador);
                }
            }

            if (vm.GoleadoresDelVisitante != null)
            {
                for (var i = 0; i < vm.GoleadoresDelVisitante.Length; i++)
                {
                    var jug      = Context.Jugadores.Find(vm.GoleadoresDelVisitante[i]);
                    var goleador = new Goleador
                    {
                        JugadorId = jug.Id,
                        EquipoId  = model.Jornada.VisitanteIdInt(),
                        Cantidad  = vm.CantidadDeGolesGoleadorVisitante[i],
                        PartidoId = model.Id
                    };
                    model.Goleadores.Add(goleador);
                }
            }
        }