Пример #1
0
        static void Create()
        {
            List <Dictionary <string, object> > list = DbConnector.Query("SELECT max(id) FROM Users;");
            int newId = (int)list[0].First().Value + 1;

            System.Console.WriteLine("Please enter the first name:");
            string fname = Console.ReadLine();

            System.Console.WriteLine("Please enter the last name:");
            string lname = Console.ReadLine();

            System.Console.WriteLine("Please enter the favorite number:");
            string favnumstr = Console.ReadLine();
            int    favnum    = Convert.ToInt32(favnumstr);

            System.Console.WriteLine("You entered the name {0} {1}, with the number {2}", fname, lname, favnum);
            System.Console.WriteLine("Is this correct? (Y/N):");
            string answer = Console.ReadLine();

            if (answer == "y" || answer == "Y" || answer == "yes" || answer == "Yes" || answer == "YES")
            {
                string insQuery = string.Format("INSERT into users (id, FirstName, LastName, FavoriteNumber) VALUES ({0}, \"{1}\", \"{2}\", {3});", newId, fname, lname, favnum);
                DbConnector.Execute(insQuery);
            }
        }
Пример #2
0
        public static void remove()
        {
            Console.WriteLine("Enter id of user you want to delete");
            string id          = Console.ReadLine();
            string removeQuery = $"DELETE FROM users WHERE id = {id}";

            DbConnector.Execute(removeQuery);
            read();
        }
Пример #3
0
        public static void create()
        {
            Console.WriteLine("What's your First Name");
            string first_name = '"' + Console.ReadLine() + '"';

            Console.WriteLine("What's your Last Name");
            string last_name = '"' + Console.ReadLine() + '"';

            Console.WriteLine("What's your Favorite Number");
            string num   = Console.ReadLine();
            string query = $"INSERT into users(first_name, last_name, favorite_number) VALUES({first_name}, {last_name}, {num})";

            Console.WriteLine(query);
            DbConnector.Execute(query);
            read();
        }
Пример #4
0
        public static void Main(string[] args)
        {
            System.Console.WriteLine("Enter first name: ");
            string fname = Console.ReadLine();
            string lname = Console.ReadLine();
            int    fnum  = Console.Read();

            DbConnector.Query("SELECT idUsers, FirstName, LastName, FavoriteNumber FROM Users");
            DbConnector.Execute("INSERT INTO Users(FirstName, LastName, FavoriteNumber) VALUES ('{fname}', '{lname}', fnum)");
            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseStartup <Startup>()
                       .Build();

            host.Run();
        }
Пример #5
0
        public static void Create()
        {
            System.Console.WriteLine("Enter first name");
            string firstName = Console.ReadLine();
            string fString   = '"' + firstName + '"';

            System.Console.WriteLine("Enter last name");
            string lastName = Console.ReadLine();
            string lString  = '"' + lastName + '"';

            System.Console.WriteLine("Enter lucky number");
            string luckyNum = Console.ReadLine();
            // string nString = '"' + luckyNum + '"';
            string insert = $"INSERT INTO users (FirstName, LastName, FavoriteNumber) VALUES ({fString}, {lString}, {luckyNum})";

            DbConnector.Execute(insert);
            Read();
        }
Пример #6
0
        public static void update()
        {
            Console.WriteLine("Enter id");
            string id = Console.ReadLine();

            Console.WriteLine("Enter First Name");
            string first_name = Console.ReadLine();
            string fString    = '"' + first_name + '"';

            Console.WriteLine("Enter Last Name");
            string last_name = Console.ReadLine();
            string lString   = '"' + last_name + '"';

            Console.WriteLine("Enter Favorite Number");
            string favorite_number = Console.ReadLine();
            string updateQuery     = $"UPDATE users SET first_name = {fString}, last_name = {lString}, favorite_number = {favorite_number} WHERE id = {id}";

            DbConnector.Execute(updateQuery);
            read();
        }
Пример #7
0
        public static void Update()
        {
            Console.WriteLine("Enter user_id");
            string id = Console.ReadLine();

            System.Console.WriteLine("Enter first name");
            string firstName = Console.ReadLine();
            string fString   = '"' + firstName + '"';

            System.Console.WriteLine("Enter last name");
            string lastName = Console.ReadLine();
            string lString  = '"' + lastName + '"';

            System.Console.WriteLine("Enter lucky number");
            string luckyNum = Console.ReadLine();
            string nString  = '"' + luckyNum + '"';
            // Why do you not need nString for this one?
            // string update = $"UPDATE users SET (FirstName, LastName, FavoriteNumber) = ({fString}), ({lString}), ({nString}) WHERE id = ({id})";
            string update = $"UPDATE users SET FirstName = {fString}, LastName = {lString}, FavoriteNumber = {nString} WHERE id = {id}";

            DbConnector.Execute(update);
        }
Пример #8
0
 public static void Create(string first, string last, int number)
 {
     DbConnector.Execute($"INSERT INTO users (FirstName, LastName, FavoriteNumber) VALUES ('{first}', '{last}', '{number}')");
     System.Console.WriteLine($"{first} {last} successfully added to the database!");
 }