Beispiel #1
0
        public static void AddOrUpdate(VideoGame game)
        {
            using (var context = new VideoGameStoreEntities())
            {
                var vg = context.VideoGames.FirstOrDefault(x => x.Name.ToLower() == game.Name.ToLower());

                if (vg == null)
                {
                    game.Id = GetAll().Max(x => x.Id) + 1;
                    context.VideoGames.Add(game);
                }

                else
                {
                    vg.Description  = game.Description;
                    vg.Name         = game.Name;
                    vg.PlatformId   = game.PlatformId;
                    vg.RatingId     = game.RatingId;
                    vg.Rented       = game.Rented;
                    vg.UPC          = game.UPC;
                    vg.ReleasedDate = game.ReleasedDate;

                    context.VideoGames.AddOrUpdate(vg);
                }

                context.SaveChanges();
            }
        }
Beispiel #2
0
 public static void Delete(VideoGame game)
 {
     using (var context = new VideoGameStoreEntities())
     {
         context.VideoGames.Remove(context.VideoGames.First(x => x.Id == game.Id));
         context.SaveChanges();
     }
 }
Beispiel #3
0
        public static IEnumerable <VideoGame> GetAll()
        {
            var videoGames = new List <VideoGame>();

            using (var context = new VideoGameStoreEntities())
            {
                videoGames.AddRange(context.VideoGames.ToList());
            }

            return(videoGames);
        }
        public static IEnumerable <Rating> GetAll()
        {
            var ratings = new List <Rating>();

            using (var context = new VideoGameStoreEntities())
            {
                ratings.AddRange(context.Ratings.ToList());
            }

            return(ratings);
        }
        public static IEnumerable <Platform> GetAll()
        {
            var platforms = new List <Platform>();

            using (var context = new VideoGameStoreEntities())
            {
                platforms.AddRange(context.Platforms.ToList());
            }

            return(platforms);
        }