public void Delete() { try { VideogamesContext context = new VideogamesContext(); context.Entry(this).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); } catch (Exception) { throw; } }
public void Remove() { try { VideogamesContext context = new VideogamesContext(); context.Entry(this).State = System.Data.Entity.EntityState.Deleted; //borramos el producto context.SaveChanges(); //guardamos los cambios } catch (Exception e) { throw; } }
public static List <Videogames> SelectAll()//metodo para listar la tabla de videojuegos { List <Videogames> videogames = new List <Videogames>(); try { VideogamesContext context = new VideogamesContext(); videogames = context.Videogames.OrderBy(x => x.name).ToList();//Ordenamos por el nombre del juego y listamos la tabla } catch (Exception e) { throw; } return(videogames); }
public static List <Videogames> ListRanking() { List <Videogames> videogames = new List <Videogames>(); try { VideogamesContext context = new VideogamesContext(); videogames = context.Videogames.OrderByDescending(x => x.score).ToList(); } catch (Exception e) { throw; } return(videogames); }
public static List <Videogames> SelectAll() { List <Videogames> videogames = new List <Videogames>(); try { VideogamesContext context = new VideogamesContext(); videogames = context.Videogames.OrderBy(x => x.name).ToList(); } catch (Exception e) { Console.WriteLine("Ha habido un error al leer la base de datos: " + e); } return(videogames); }
public static List <Videogames> Ranking() { List <Videogames> ranking = new List <Videogames>(); try { VideogamesContext context = new VideogamesContext(); ranking = context.Videogames.OrderByDescending(x => x.score).ToList(); } catch (Exception e) { Console.WriteLine("Ha habido un error al leer la base de datos: " + e); } return(ranking); }
public static Videogames Get(int id) { Videogames videogame = new Videogames(); try { VideogamesContext context = new VideogamesContext(); videogame = context.Videogames.Where(x => x.id == id).SingleOrDefault(); } catch (Exception) { throw; } return(videogame); }
public static Videogames GetVideoGame(int id) { Videogames videogames = null; try { VideogamesContext context = new VideogamesContext(); videogames = context.Videogames.Where(x => x.id == id).SingleOrDefault();//devolvemos el videojuego que tenga la id dada } catch (Exception e) { throw; } return(videogames); }
public void Save() { bool create = this.id == 0; try { VideogamesContext context = new VideogamesContext(); if (create) { context.Entry(this).State = System.Data.Entity.EntityState.Added; } else { context.Entry(this).State = System.Data.Entity.EntityState.Modified; } context.SaveChanges(); } catch (Exception) { throw; } }
public void Save() { bool crear = this.id == 0;//sera verdadero cuando la id sea 0 try { VideogamesContext context = new VideogamesContext(); //creamos el contexto if (crear) //si se cumple crear(Su id es 0, por lo tanto es nuevo) { context.Entry(this).State = System.Data.Entity.EntityState.Added; //añadimos el producto } else//sino... { context.Entry(this).State = System.Data.Entity.EntityState.Modified;//modificamos el producto } context.SaveChanges(); //lo guardamos } catch (Exception e) { throw; } }