public List <VideoGame> getAll()
 {
     using (var db = new VideoGameContext())
     {
         return(db.VideoGames.ToList());
     }
 }
示例#2
0
        private static void FillAllTables()
        {
            using (var context = new VideoGameContext())
            {
                context.Games.Add(firstGame);
                context.Games.Add(secondGame);
                context.Games.Add(thirdGame);
                context.Games.Add(fourthGame);
                context.Games.Add(fifthGame);
                context.Games.Add(sixthGame);
                context.Games.Add(seventhGame);

                context.Users.Add(firstUser);
                context.Users.Add(secondUser);

                context.Ratings.Add(firstRating);
                context.Ratings.Add(secondRating);
                context.Ratings.Add(thirdRating);
                context.Ratings.Add(fourthRating);
                context.Ratings.Add(fifthRating);
                context.Ratings.Add(sixthRating);
                context.Ratings.Add(seventhRating);

                context.SaveChanges();
            }
        }
示例#3
0
        /// <exception cref="DbUpdateException">  An error is encountered while saving to the database. </exception>
        /// <exception cref="DbUpdateConcurrencyException">
        ///                 A concurrency violation is encountered while saving to the database.
        ///                 A concurrency violation occurs when an unexpected number of rows are affected during save.
        ///                 This is usually because the data in the database has been modified since it was loaded into memory.
        ///             </exception>
        public static async void InjectAsync(VideoGameContext context)
        {
            await InitializePlatforms(context);
            await InitalizeGames(context);
            await InitailizeGamePlatforms(context);

            await context.SaveChangesAsync();
        }
        public bool updateVideoGame(VideoGame videoGame)
        {
            using (var db = new VideoGameContext())
            {
                var videoGameTarget = db.VideoGames.Where(vg => vg.VideoGameId == videoGame.VideoGameId).FirstOrDefault();

                try
                {
                    db.Entry(videoGameTarget).CurrentValues.SetValues(videoGame);
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
示例#5
0
 public PublisherController(VideoGameContext context)
 {
     _context = context;
 }
 public GameRepository(VideoGameContext videoGameContext,
                       IFileManager fileManager)
 {
     _videoGameContext = videoGameContext;
     _fileManager      = fileManager;
 }
示例#7
0
        public static void ShowAllGames()
        {
            using (var context = new VideoGameContext())
            {
                var allGames   = context.Games.ToList();
                var allRatings = context.Ratings.ToList();

                if (allGames.Count % QUANTITY_IN_PAGE == 0)
                {
                    int j = 1;
                    for (int i = 0; i < allGames.Count / QUANTITY_IN_PAGE; i++)
                    {
                        var gamesTemp = allGames.OrderBy(i => i.Name).Skip(i * QUANTITY_IN_PAGE).Take(QUANTITY_IN_PAGE).ToList();
                        Console.WriteLine($"\t- page {i + 1} -\n");
                        foreach (var game in gamesTemp)
                        {
                            var rating = allRatings.Where(g => g.Game.Equals(game)).ToList();
                            Console.WriteLine($"Название: {game.Name}");
                            if (rating.Count > 0)
                            {
                                Console.WriteLine($"Рейтинг: {rating.Sum(r => r.Grade) / rating.Count}/5");
                            }
                            else
                            {
                                Console.WriteLine($"Рейтинг: -/5");
                            }
                            Console.WriteLine($"Разработчик: {game.Developer}");
                            Console.WriteLine($"Описание: {game.Description}");
                            Console.WriteLine("\n");
                            j++;
                        }
                        Console.WriteLine();
                    }
                }
                else
                {
                    int j = 1;
                    for (int i = 0; i < allGames.Count / QUANTITY_IN_PAGE + 1; i++)
                    {
                        var gamesTemp = allGames.OrderBy(i => i.Name).Skip(i * QUANTITY_IN_PAGE).Take(QUANTITY_IN_PAGE).ToList();
                        Console.WriteLine($"\t- page {i + 1} -\n");
                        foreach (var game in gamesTemp)
                        {
                            var rating = allRatings.Where(g => g.Game.Equals(game)).ToList();
                            Console.WriteLine($"Название: {game.Name}");
                            if (rating.Count > 0)
                            {
                                Console.WriteLine($"Рейтинг: {rating.Sum(r => r.Grade) / rating.Count}/5");
                            }
                            else
                            {
                                Console.WriteLine($"Рейтинг: -/5");
                            }
                            Console.WriteLine($"Разработчик: {game.Developer}");
                            Console.WriteLine($"Описание: {game.Description}");
                            Console.WriteLine("\n");
                            j++;
                        }
                        Console.WriteLine();
                    }
                }
            }
        }
 public VideoGameListingsController(VideoGameContext context)
 {
     _context = context;
 }
 public GenreController(VideoGameContext context)
 {
     _context = context;
 }
示例#10
0
 /// <exception cref="AggregateException">At least one of the <see cref="T:System.Threading.Tasks.Task"></see> instances was canceled. If a task was canceled, the <see cref="T:System.AggregateException"></see> exception contains an <see cref="T:System.OperationCanceledException"></see> exception in its <see cref="P:System.AggregateException.InnerExceptions"></see> collection.   -or-   An exception was thrown during the execution of at least one of the <see cref="T:System.Threading.Tasks.Task"></see> instances.</exception>
 /// <exception cref="DbUpdateException">An error is encountered while saving to the database. </exception>
 /// <exception cref="DbUpdateConcurrencyException">
 ///     A concurrency violation is encountered while saving to the database.
 ///     A concurrency violation occurs when an unexpected number of rows are affected during save.
 ///     This is usually because the data in the database has been modified since it was loaded into memory.
 /// </exception>
 /// <exception cref="ObjectDisposedException">One or more of the <see cref="T:System.Threading.Tasks.Task"></see> objects in <paramref name="tasks">tasks</paramref> has been disposed.</exception>
 /// <exception cref="ArgumentNullException">The <paramref name="tasks">tasks</paramref> argument is null.</exception>
 /// <exception cref="ArgumentException">The <paramref name="tasks">tasks</paramref> argument contains a null element.   -or-   The <paramref name="tasks">tasks</paramref> argument is an empty array.</exception>
 public static void Inject(VideoGameContext context)
 {
     Task.WaitAll(InitializePlatforms(context), InitalizeGames(context), InitailizeGamePlatforms(context));
     context.SaveChanges();
 }
示例#11
0
 public ConstructorTests()
 {
     dbContextOptions = new DbContextOptions <VideoGameContext>();
     context          = new VideoGameContext(dbContextOptions);
 }
 public ConsoleController(VideoGameContext context)
 {
     _context = context;
 }