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("Неккоректный ввод! Повторите попытку: "); } } } }
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); }
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); }
private void UpdateAllGames(Contex contex) { var games = contex.VideoGames.ToList(); games.ForEach(x => UpdateAvgRating(contex, x)); }
public int GetPageCount(Contex contex) { var allGames = contex.VideoGames.ToList(); return (int)Math.Ceiling(allGames.Count / (double)INDEX_PAGE); }
public void ShowPages(Contex contex, int pageNumber = 1) { Console.WriteLine($" {pageNumber} | {GetPageCount(contex)}"); }