コード例 #1
0
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", false, true);

            IConfigurationRoot configurationRoot = builder.Build();

            var connectionString = configurationRoot.GetConnectionString("DebugConnectionString");

            using (var contex = new Contex(connectionString))
            {
                var search     = new SearchService();
                var pageNumber = 0;
                search.ShowGames(contex);
                while (true)
                {
                    Console.Write("Введите номер страницы: ");
                    if (int.TryParse(Console.ReadLine(), out pageNumber) && search.GetPageCount(contex) >= pageNumber && pageNumber > 0)
                    {
                        search.ShowGames(contex, pageNumber);
                    }
                    else
                    {
                        Console.Write("Неккоректный ввод! Повторите попытку: ");
                    }
                }
            }
        }
コード例 #2
0
 private void UpdateAvgRating(Contex contex, Game game)
 {
     var ratings = contex.Ratings.Where(x=>x.VideoGame==game).ToList();
     var sumRating = 0;
     ratings.ForEach(x => sumRating += x.GameRating);
     game.AvgRating = sumRating / (double)ratings.Count;
     contex.VideoGames.Update(game);
 }
コード例 #3
0
 public void ShowGames(Contex contex, int pageNumber = 1)
 {
     UpdateAllGames(contex);
     var games = contex.VideoGames.Skip(INDEX_PAGE * --pageNumber).Take(INDEX_PAGE).ToList();
     Console.Clear();
     games.ForEach(x => Console.WriteLine($"Name: {x.Name}\nDescription: {x.Description}\nAvg rating: {x.AvgRating}\n"));
     ShowPages(contex, ++pageNumber);
 }
コード例 #4
0
 private void UpdateAllGames(Contex contex)
 {
     var games = contex.VideoGames.ToList();
     games.ForEach(x => UpdateAvgRating(contex, x));
 }
コード例 #5
0
 public int GetPageCount(Contex contex)
 {
     var allGames = contex.VideoGames.ToList();
     return (int)Math.Ceiling(allGames.Count / (double)INDEX_PAGE);
 }
コード例 #6
0
 public void ShowPages(Contex contex, int pageNumber = 1)
 {
     Console.WriteLine($" {pageNumber} | {GetPageCount(contex)}");
 }