コード例 #1
0
        static void Main(string[] args)
        {
            ConfigurationService.Init();

            using (var playerDataAccess = new PlayerDataAccess())
            {
                foreach (var player in playerDataAccess.Select())
                {
                    Console.WriteLine($"[{player.Number}]{player.FullName}");
                }

                var teamDataAccess = new TeamDataAccess();

                var result = teamDataAccess.Select();

                playerDataAccess.Insert(new Player {
                    FullName = "Петя", Number = 5, TeamId = result.First().Id
                });

                teamDataAccess.Dispose();

                Console.WriteLine();

                foreach (var player in playerDataAccess.Select())
                {
                    Console.WriteLine($"[{player.Number}]{player.FullName}");
                }
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            InitConfiguration();

            var player = new Player
            {
                FullName = "Maks",
                Number   = 23,
                TeamId   = new Guid("7E7E5C30-7B47-4A8E-A4E4-14664A83A55D")
            };

            using (var context = new PlayerDataAccess())
            {
                context.Insert(player);
                var players = context.Select();

                foreach (var plaer in players)
                {
                    Console.WriteLine($"{plaer.FullName}");
                }
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            //create a new instance of the player data access

            PlayerDataAccess data = new PlayerDataAccess();

            //communcitae with our end user
            Console.WriteLine("What would you like to do?");
            Console.WriteLine("View Playerss (V)?");
            Console.WriteLine("Delete a player form the database (D)?");

            string choice = Console.ReadLine().ToUpper();

            //enter the swicth case which will decide the method to call
            //based on the value of choice
            switch (choice)
            {
            case "V":
                //calling the player class placing it in a list
                //crating a new instacnce of the player class in a list
                List <player> PlayerToView = new List <player>();
                //call the view all players method and add
                //value to the player to view list
                PlayerToView = data.GetAllPlayers();
                //loop through the PlayerToView list and write out all the values
                foreach (player singleplayer in PlayerToView)
                {
                    //Console.WriteLine("{0:MM/dd/yyyy}", singleplayer.birthdate);
                    Console.WriteLine(singleplayer.PlayerID + " " + singleplayer.Lastname + " " + singleplayer.Firstname
                                      + " " + singleplayer.height + " " + singleplayer.birthdate.ToString("MM/dd/yyyy") + " " + singleplayer.TeamName);
                }
                Console.ReadLine();
                break;

            //this will run when the user inputs D into the choice variable
            case "D":
                //prompt user for input
                Console.WriteLine("Enter the ID of the player you would like to delete");
                //converting users inpout to an integer
                int deletechoice = Convert.ToInt32(Console.ReadLine());
                //calling the player class and creaiting
                //an new instance of player class
                player deleteplayer = new player();
                //place the value of deletchoice into the player class
                deleteplayer.PlayerID = deletechoice;
                //call the delete player method from playerdataaccess
                //pass the player class named delete player to the method
                bool check = data.DeletePlayer(deleteplayer);
                if (check == true)
                {
                    Console.WriteLine("You have successfully deleted a player form the database.");
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("Your delete failed.");
                    Console.ReadLine();
                }
                break;

            default:
                Console.WriteLine("You have entered an incorrect value try entering V or D");
                Console.ReadLine();
                break;
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: aravinda-kumar/HealthStats
        static void Main(string[] args)
        {
            //create a new instance of the player data access
            PlayerDataAccess data = new PlayerDataAccess();

            //communticate with our end user
            Console.WriteLine("What would you like to do?");
            Console.WriteLine("View Players (V)?");
            Console.WriteLine("Delete fromt the database (D)?");

            string
                choice = Console.ReadLine().ToUpper();

            //enter the switch case which will decide the method to call based on the value of the choice
            switch (choice)
            {
            case "V":
                //calling the player class placing it in a list
                //creating a new instance of the player class in a list
                List <PlayerDAO> PlayerToView = new List <PlayerDAO>();
                //call the view all players method and add value to the player to view list
                PlayerToView = data.GetAllPlayers();
                //loop through the PlayerToView list and write out all the values
                foreach (PlayerDAO singleplayer in PlayerToView)
                {
                    Console.WriteLine(singleplayer.PlayerID + " " + singleplayer.FirstName + " " + singleplayer.LastName);
                }
                Console.ReadLine();
                break;

            //this will run when the user inputs D into the choice variable
            case "D":
                // Prompt user for input
                Console.WriteLine("Enter the ID of the PlayerDAO you would like to delete");
                //converting users input to an interger
                int deletechoice = Convert.ToInt32(Console.ReadLine());
                // calling the player class and creating a new instance of player class (instanciating)
                PlayerDAO deleteplayer = new PlayerDAO();
                // Place the value of delete choice into the player class
                deleteplayer.PlayerID = deletechoice;
                // Call the delete player method from playerdataaccess
                //pass the player class named delete player to the method
                bool check = data.DeletePlayer(deleteplayer);
                if (check == true)
                {
                    Console.WriteLine("You have deleted a PlayerDAO from the database");
                }
                else
                {
                    Console.WriteLine("FAILED to delete");
                }


                break;



            default:
                Console.WriteLine("You have entered an invalid value, try entering 'V' or 'D'");
                Console.ReadLine();
                break;
            }
        }