public void Delete() { try { GamesDBContext context = new GamesDBContext(); context.Entry(this).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); } catch (Exception) { throw; } }
public static List <Videogames> SelectAll() { List <Videogames> videogames = new List <Videogames>(); try { GamesDBContext context = new GamesDBContext(); videogames = context.Videogames.OrderBy(x => x.name).ToList(); } catch (Exception) { throw; } return(videogames); }
public static Videogames Get(int id) { Videogames videogames = new Videogames(); try { GamesDBContext context = new GamesDBContext(); videogames = context.Videogames.Where(x => x.id == id).SingleOrDefault(); } catch (Exception) { throw; } return(videogames); }
public static List <Videogames> SelectRanking() { List <Videogames> videogames = new List <Videogames>(); try { GamesDBContext context = new GamesDBContext(); videogames = context.Videogames.OrderByDescending(x => x.score).ToList(); } catch (Exception) { throw; } return(videogames); }
public ActionResult Search(string word) { IEnumerable <Videogames> videogames; using (var bd = new GamesDBContext()) { videogames = bd.Videogames; if (!string.IsNullOrEmpty(word)) { videogames = videogames.Where(x => x.name.ToLower().Contains(word.ToLower())); videogames = videogames.ToList(); return(View(videogames)); } else { return(Redirect("~/")); } } }
public void Save() { bool create = this.id == 0; try { GamesDBContext context = new GamesDBContext(); 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; } }