Exemplo n.º 1
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();
     }
 }
Exemplo n.º 2
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();
            }
        }