Example #1
0
        public void AgregarConsolas(ConsolasDTO consolasDTO)
        {
            using (var dbContext = new TrailersdeVideoJuegosEntities())
            {
                var nuevaConsola = new Consola();

                nuevaConsola.Nombre = consolasDTO.Nombre;

                dbContext.Consola.Add(nuevaConsola);

                dbContext.SaveChanges();

            }
        }
Example #2
0
        public void AgregarGeneros(GenerosDTO generosDTO)
        {
            using (var dbContext = new TrailersdeVideoJuegosEntities())
            {
                var nuevoGenero = new Genero();

                nuevoGenero.Nombre = generosDTO.Nombre;

                dbContext.Genero.Add(nuevoGenero);

                dbContext.SaveChanges();

            }
        }
Example #3
0
        public void EliminarConsola(int consolaId)
        {
            using (var dbContext = new TrailersdeVideoJuegosEntities())
            {
                var consola = dbContext.Consola.FirstOrDefault(r => r.Id == consolaId);

                if (consola != null)
                {
                    dbContext.Consola.Remove(consola);

                    dbContext.SaveChanges();
                }

            }
        }
Example #4
0
        public void EliminarGenero(int generoId)
        {
            using (var dbContext = new TrailersdeVideoJuegosEntities())
            {
                var genero = dbContext.Genero.FirstOrDefault(r => r.Id == generoId);

                if (genero != null)
                {
                    dbContext.Genero.Remove(genero);

                    dbContext.SaveChanges();
                }

            }
        }
Example #5
0
        public void AgregarJuegos(JuegosDTO juegosDTO)
        {
            using (var dbContext = new TrailersdeVideoJuegosEntities())
            {
                //var nuevoJuego = new Juego();

                //nuevoJuego.Nombre = juegosDTO.Nombre;


                var nuevoJuego = Mapper.Map<Juego>(juegosDTO);
                nuevoJuego.Imagenes = Mapper.Map<ICollection<Imagenes>>(juegosDTO.ListaImagenes);

                dbContext.Juego.Add(nuevoJuego);

                dbContext.SaveChanges();

            }
        }
Example #6
0
        public void ActualizarConsolas(ConsolasDTO consolasDTO)
        {
            using (var dbContext = new TrailersdeVideoJuegosEntities())
            {
                var consola = dbContext.Consola.FirstOrDefault(r => r.Id == consolasDTO.Id);

                if (consola != null)
                {
                    consola.Nombre = consolasDTO.Nombre;
                    dbContext.SaveChanges();

                }
                else
                {

                   
                }
            }
        }
Example #7
0
        public void ActualizarGeneros(GenerosDTO generosDTO)
        {
            using (var dbContext = new TrailersdeVideoJuegosEntities())
            {
                var genero = dbContext.Genero.FirstOrDefault(r => r.Id == generosDTO.Id);

                if (genero != null)
                {
                    genero.Nombre = generosDTO.Nombre;
                    dbContext.SaveChanges();

                }
                else
                {

                   
                }
            }
        }
Example #8
0
        public void EliminarJuego(int juegoId)
        {
            using (var dbContext = new TrailersdeVideoJuegosEntities())
            {
                var juego = dbContext.Juego.FirstOrDefault(r => r.Id == juegoId);

                if (juego != null)
                {
                    while (juego.Imagenes.Any())
                    {
                        var imagen = juego.Imagenes.First();

                        dbContext.Imagenes.Remove(imagen);
                    }

                    dbContext.Juego.Remove(juego);

                    dbContext.SaveChanges();
                }
            }
        }
Example #9
0
         public void ActualizarJuegos(JuegosDTO juegosDTO)
        {
            using (var dbContext = new TrailersdeVideoJuegosEntities())
            {
                var juego = dbContext.Juego.FirstOrDefault(r => r.Id == juegosDTO.Id);

                if (juego != null)
                {
                    //juego = Mapper.Map<Juego>(juegoDTO); //Crea una nueva instancia
                    Mapper.Map(juegosDTO, juego); //Actualiza la entidad

                    //juego.Imagenes = Mapper.Map<ICollection<Imagenes>>(juegoDTO.ListaImagenes);
                    Mapper.Map(juegosDTO.ListaImagenes, juego.Imagenes);

                    //Remover las imagenes marcadas como eliminadas
                    if (juegosDTO.ListaImagenes != null)
                    {
                        foreach (var imagen in juegosDTO.ListaImagenes)
                        {
                            if (imagen.ImagenEliminada)
                            {
                                var eliminarImagen = juego.Imagenes.FirstOrDefault(r => r.Id == imagen.Id);
                                if (eliminarImagen != null)
                                {
                                    juego.Imagenes.Remove(eliminarImagen);
                                }
                            }
                        }
                    }

                    dbContext.SaveChanges();
                }
            }
        }