static void Main(string[] args) { //opens the connection to SQL via the UsersController constructor UsersController UserCtrl = new UsersController(@"STUDENT03\SQLEXPRESS", "prssql"); VendorsController VendorCtrl =new VendorsController(@"STUDENT03\SQLEXPRESS", "prssql"); //VENDOR CODE STARTS HERE //returns the list of all vendors in the Vendor table in prssql database Console.WriteLine("List of all vendors:"); IEnumerable<Vendor> vendors = VendorCtrl.List(); foreach (Vendor vendor1 in vendors) { Console.WriteLine($"{vendor1.Code} {vendor1.Name}"); } //get the vendor with id number in "VendorCtrl.Get(#) Console.WriteLine("-----------------------------------------------"); Vendor vendor = VendorCtrl.Get(3); if (vendor == null) { Console.WriteLine("Vendor not found"); } else { Console.WriteLine($"Id {vendor.Id} is {vendor.Code} {vendor.Name}"); Console.WriteLine("-----------------------------------------------"); } //Begin adding a vendor code here Console.WriteLine("-----------------------------------------------"); //Vendor newVendor = new Vendor("NOVN", "Novan", "4105 Hopson Road", "Morrisville", "NC", "27560", "919-485-8080", "*****@*****.**", true, true); //add newVendor to the database //bool vendorAddSuccess = VendorCtrl.Create(newVendor); //commented out so this won't keep adding to the DB //END adding a vendor code here //changing/updating the data in the vendor table vendor = VendorCtrl.Get(6); vendor.Email = "*****@*****.**"; bool VendorChangeSuccess = VendorCtrl.Change(vendor); //delete a vendor //vendor = VendorCtrl.Get(6); //bool VendorDeleteSuccess = VendorCtrl.Remove(vendor); //VENDOR CODE ENDS HERE ///////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //USER CODE BELOW HERE //returns the list of all users in the [User] table in prssql database Console.WriteLine("List of all users:"); IEnumerable<User> users = UserCtrl.List(); foreach (User user1 in users) { Console.WriteLine($"{user1.Firstname} {user1.Lastname}"); } //get the user with id number in "UserCtrl.Get(#) Console.WriteLine("-----------------------------------------------"); User user = UserCtrl.Get(11); if (user == null) { Console.WriteLine("User not found"); } else { Console.WriteLine($"Id {user.Id} is {user.Firstname} {user.Lastname}"); } //intentionally putting in bad user id to see if it returns User not found Console.WriteLine("-----------------------------------------------"); //get the user with id number in "UserCtrl.Get(#) User user2 = UserCtrl.Get(99); if (user2 == null) { Console.WriteLine("User not found"); } else { Console.WriteLine($"Id {user2.Id} is {user2.Firstname} {user2.Lastname}"); } //CREATE NEW USER// //User newUser = new User(); //newUser.Username = "******"; //newUser.Password = "******"; //newUser.Firstname = "New"; //newUser.Lastname = "User"; //newUser.Phone = "555-1234"; //newUser.Email = "*****@*****.**"; //newUser.IsReviewer = true; //newUser.IsAdmin = false; //newUser.Active = false; //add new user to the database// //bool success = UserCtrl.Create(newUser); //END CREATE NEW USER// //changing/updating the data in the user table user = UserCtrl.Get(3); user.Firstname= "user3"; bool success = UserCtrl.Change(user); //delete a user //user = UserCtrl.Get(13); //success = UserCtrl.Remove(user); //closes the active connection to SQL UserCtrl.CloseConnection(); }
static void Main(string[] args) { VendorsController VendorCtrl = new VendorsController(@"dsi-workstation\SQLEXPRESS", "prssql"); IEnumerable <Vendor> vendors = VendorCtrl.List(); Vendor v1 = VendorCtrl.Get(1); int AmazonId = v1.Id; v1.Name = "Amazon, Inc."; VendorCtrl.Change(v1); v1.Id = 0; v1.Name = "Walmart"; v1.Code = "WALM"; VendorCtrl.Create(v1); v1.Id = 3; VendorCtrl.Remove(v1); VendorCtrl.CloseConnection(); /* * UsersController UserCtrl = new UsersController(@"dsi-workstation\SQLEXPRESS", "prssql"); * * IEnumerable<User> users = UserCtrl.List(); * foreach(User user1 in users) { * Console.WriteLine($"{user1.Firstname} {user1.Lastname}"); * } * * User user = UserCtrl.Get(6); * if(user == null) { * Console.WriteLine("User not found"); * } else { * Console.WriteLine($"{user.Firstname} {user.Lastname}"); * } * * user = UserCtrl.Get(999); * if (user == null) { * Console.WriteLine("User not found"); * } else { * Console.WriteLine($"{user.Firstname} {user.Lastname}"); * } * * User newUser = new User(); * newUser.Username = "******"; * newUser.Password = "******"; * newUser.Firstname = "New"; * newUser.Lastname = "User"; * newUser.Phone = "513-555-1212"; * newUser.Email = "*****@*****.**"; * newUser.IsReviewer = false; * newUser.IsAdmin = true; * * //bool success = UserCtrl.Create(newUser); * * user = UserCtrl.Get(6); * user.Firstname = "Kimmie"; * //bool success = UserCtrl.Change(user); * * user = UserCtrl.Get(19); * if(user != null) * UserCtrl.Remove(user); * * UserCtrl.CloseConnection(); * */ }