Beispiel #1
0
        static void ActnVendor()
        {
            //Returns all
            VendorsController    VendorCtrl = new VendorsController(@"STUDENT50\SQLEXPRESS", "prssql");
            IEnumerable <Vendor> vendor     = VendorCtrl.List();

            foreach (Vendor Vendor1 in vendor)
            {
                Console.WriteLine($"{Vendor1.Code} {Vendor1.Name} {Vendor1.Address}");
            }

            Vendor Amzn = VendorCtrl.Get(1);

            if (Amzn == null)
            {
                Console.WriteLine("Vendor not found");
            }
            else
            {
                Console.WriteLine($"{Amzn.Code} {Amzn.Name} {Amzn.Address}");
            }

            Amzn = VendorCtrl.Get(999);
            if (Amzn == null)
            {
                Console.WriteLine("User not found");
            }
            else
            {
                Console.WriteLine($"{Amzn.Code} {Amzn.Name} {Amzn.Address}");
            }

            Vendor newVendor = new Vendor()
            {
                Code          = "Walm",
                Address       = "564 Walmart way",
                Name          = "Walmart",
                City          = "Walmartville",
                State         = "GA",
                Zip           = "98123",
                Email         = "*****@*****.**",
                Phone         = "987-456-1203",
                Active        = true,
                IsPreapproved = true
            };
            //bool success = VendorCtrl.Create(newVendor);

            Vendor vendorWal = VendorCtrl.Get(5);

            vendorWal.Code = "WAL";
            //bool success = VendorCtrl.Change(vendorWal);


            bool success = VendorCtrl.Remove(vendorWal);

            VendorCtrl.CloseConnection();
        }
		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();
		}
Beispiel #3
0
        static void Main(string[] args)
        {
            UsersController UserCtrl = new SqlLibrary.UsersController(@"STUDENT12\SQLEXPRESS", "PRSDatabase");

            //	IEnumerable<User> users = UserCtrl.List();
            //	foreach (User user1 in users) {
            //		Console.WriteLine($"{user1.FirstName} {user1.LastName}");
            //}

            //User user = UserCtrl.Get(5);
            //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 = "Last";
            //newUser.LastName = "first";
            //newUser.Phone = "513-555-0000";
            //newUser.Email = "newuser@gmail";
            //newUser.IsReviewer = true;
            //newUser.IsAdmin = true;
            //newUser.Active = true;

            //bool success = UserCtrl.Create(newUser);

            //User user = UserCtrl.Get(5);
            //user.FirstName = "Harvy";
            //bool success = UserCtrl.Change(user);

            //user = UserCtrl.Get(10);
            //success = UserCtrl.Remove(user);

            //UserCtrl.CloseConection();



            VendorsController vendorctrl = new VendorsController(@"STUDENT12\SQLEXPRESS", "PRSDatabase");

            IEnumerable <Vendor> Vendors = vendorctrl.List();

            foreach (Vendor vendors in Vendors)
            {
                Console.WriteLine($"{vendors.Code} {vendors.Name}");
            }

            //Vendor newVendor = new Vendor();
            //newVendor.Code = "EGG"; //Must be a unique value
            //newVendor.Name = "New Egg";
            //newVendor.Address = "123 Main Street";
            //newVendor.City = "Cincinnati";
            //newVendor.State = "OH";
            //newVendor.Zip = "45002";
            //newVendor.Phone = "nani";
            //newVendor.Email = "nano";
            //newVendor.IsPreApproved = true;

            //bool success = vendorctrl.Create(newVendor);
            //Console.WriteLine($"New vendor successfully added = {success}");

            //Vendor vendor = vendorctrl.Get(2);
            //vendor.Code = "TAR";
            //success = vendorctrl.Change(vendor);

            Vendor vendordlt = vendorctrl.Get(12);
            bool   deleted   = vendorctrl.Remove(vendordlt);

            Console.WriteLine($"Vendor Successfully removed = {deleted}");
        }
Beispiel #4
0
        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();
 *
 */
        }