Пример #1
0
 static List <Names> LoadNames()
 {
     using (var context = new PWS_NamesContext())
     {
         return(context.Names.ToList());
     }
 }
Пример #2
0
 static private void UpdateDBTopBool(int id)
 {
     using (var context = new PWS_NamesContext())
     {
         var item = context.Names.First(f => f.NameId == id);
         item.TopBool = true;
         item.TopCount++;
         context.SaveChanges();
     }
 }
Пример #3
0
        static void ViewSingleWinner(List <Names> names)
        {
            Console.Clear();
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write($"\tWin History");
            Console.ResetColor();
            Console.WriteLine("\n");

            using (var context = new PWS_NamesContext())
            {
                var wh = context.WinHistory
                         .OrderByDescending(x => x.WinHistoryId).ToList();

                var winners = names.FindAll(x => x.Wins > 0);

                var combined = (from n in winners
                                join w in wh on n.NameId equals w.NameId into gj
                                orderby n.Name
                                select new
                {
                    cName = n.Name,
                    cWH = gj
                }).ToList();

                foreach (var item in combined)
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine($"  {item.cName}:");
                    Console.ResetColor();
                    foreach (var elem in item.cWH)
                    {
                        Console.WriteLine($"\t{elem.WinDate:MM/dd/yyyy}");
                    }

                    Console.WriteLine("\n");
                }
            }
        }
Пример #4
0
        static void SetTournamentWinner(List <Names> names)
        {
            Console.Clear();
            Console.WriteLine($"\nFull Name List");
            PrintNameList(names);

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write("\n\nEnter PlayerID of the record that you want to update.\n\n");
            Console.ResetColor();

            bool validId = false;
            int  value   = 0;

            do
            {
                value = GetInputInt();

                if (value >= 1 && value <= 60)
                {
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.BackgroundColor = ConsoleColor.White;
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("Updating the database...");
                    Console.ResetColor();
                    Console.ResetColor();
                    Console.WriteLine();
                    validId = true;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("\n\nInvalid PlayerID. Please try again.\n\n");
                    Console.ResetColor();
                    validId = false;
                }
            } while (!validId);


            using (var context = new PWS_NamesContext())
            {
                var item = context.Names.First(f => f.NameId == value);
                item.Wins++;
                item.DateWin = DateTime.Now;

                context.WinHistory.Add(new WinHistory
                {
                    NameId  = item.NameId,
                    WinDate = item.DateWin
                });

                context.SaveChanges();

                Console.WriteLine();
                Console.BackgroundColor = ConsoleColor.White;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write($"{item.Name}'s win count has been updated!");
                Console.ResetColor();
                Console.ResetColor();

                Console.WriteLine();
                Console.WriteLine();
                Console.BackgroundColor = ConsoleColor.White;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write($"History table has been updated");
                Console.ResetColor();
                Console.ResetColor();
                Thread.Sleep(1000);

                Console.WriteLine();
                PrintPlayerWins(item);
                Console.ResetColor();
            }
        }