示例#1
0
 public override IEnumerable <Genre> GetAll()
 {
     using (ComputerGamesEntities myDb = new ComputerGamesEntities())
     {
         var allItems = myDb.Genres.ToList();
         return(allItems);
     }
 }
示例#2
0
 public bool IsNameExist(Genre item)
 {
     using (ComputerGamesEntities myDb = new ComputerGamesEntities())
     {
         var itemByName = myDb.Genres.Where(x => x.GenreName == item.GenreName).FirstOrDefault();
         return(itemByName == null?false:true);
     }
 }
示例#3
0
 public override Genre GetById(int id)
 {
     using (ComputerGamesEntities myDb = new ComputerGamesEntities())
     {
         var itemById = myDb.Genres.Find(id);
         return(itemById);
     }
 }
示例#4
0
 /// <summary>
 /// check if publisher with specific Id has rows in the game table
 /// </summary>
 /// <param name="publisherId"></param>
 /// <returns></returns>
 public bool IsPublisherIncluded(int publisherId)
 {
     using (ComputerGamesEntities myDb = new ComputerGamesEntities())
     {
         var itemById = myDb.Games.Where(x => x.PublisherID == publisherId).FirstOrDefault();
         return(itemById == null ? false : true);
     }
 }
示例#5
0
 public Publisher GetByPublisherLicense(int licenseNumber)
 {
     using (ComputerGamesEntities myDb = new ComputerGamesEntities())
     {
         var itemByLicense = myDb.Publishers.Where(x => x.LicenseNumber == licenseNumber).FirstOrDefault();
         return(itemByLicense);
     }
 }
示例#6
0
 public override int Add(Genre item)
 {
     using (ComputerGamesEntities myDb = new ComputerGamesEntities())
     {
         myDb.Genres.Add(item);
         myDb.SaveChanges();
         return(1);
     }
 }
示例#7
0
 public bool IsNameAndYearUnique(Game item)
 {
     using (ComputerGamesEntities myDb = new ComputerGamesEntities())
     {
         var  searchResult = myDb.Games.Where(x => (x.GameName == item.GameName) && (x.YearOfProduction == item.YearOfProduction)).FirstOrDefault();
         bool isUnique     = searchResult == null ? true : false;
         return(isUnique);
     }
 }
示例#8
0
 public override bool Delete(Game item)
 {
     using (ComputerGamesEntities myDb = new ComputerGamesEntities())
     {
         myDb.Games.Remove(item);
         myDb.SaveChanges();
         return(true);
     }
 }
示例#9
0
 public override bool Update(Genre item)
 {
     using (ComputerGamesEntities myDb = new ComputerGamesEntities())
     {
         var itemToUpdateById = myDb.Genres.Find(item.Id);
         myDb.Entry(itemToUpdateById).CurrentValues.SetValues(item);
         myDb.SaveChanges();
         return(true);
     }
 }
示例#10
0
 public override bool Delete(Genre item)
 {
     using (ComputerGamesEntities myDb = new ComputerGamesEntities())
     {
         var itemToUpdateById = myDb.Genres.Find(item.Id);
         myDb.Genres.Remove(item);
         myDb.SaveChanges();
         return(true);
     }
 }
示例#11
0
 public override bool Delete(Publisher item)
 {
     using (ComputerGamesEntities myDb = new ComputerGamesEntities())
     {
         var itemToDelete = myDb.Publishers.Find(item.Id);
         myDb.Publishers.Remove(itemToDelete);
         myDb.SaveChanges();
         return(true);
     }
 }
示例#12
0
        public IEnumerable <Game> GetGameByPublisherLicense(int licenseNumber)
        {
            using (ComputerGamesEntities myDb = new ComputerGamesEntities())
            {
                // var result = myDb.Games.Join(myDb.Publishers, game => game.PublisherID, publisher => publisher, (game) => new { Name = game.GameName });

                var result = myDb.Games.Include(game => game.Publisher).Where(publ => publ.Publisher.LicenseNumber == licenseNumber).ToList();

                return(result);
            }
        }
示例#13
0
 public override bool Update(Publisher item)
 {
     using (ComputerGamesEntities myDb = new ComputerGamesEntities())
     {
         var itemToUpdateById = myDb.Publishers.Find(item.Id);
         myDb.Entry(itemToUpdateById).CurrentValues.SetValues(item);
         // myDb.Entry(itemToUpdateById).State= EntityState.Modified;
         myDb.SaveChanges();
         return(true);
     }
 }