static void Main(string[] args) { string defaultKey = File.ReadAllText("appsettings.Debug.JSON"); JObject jObject = JObject.Parse(defaultKey); JToken token = jObject["DefaultConnection"]; string connectionString = token.ToString(); ProductRepo.connString = connectionString; ProductRepo repo = new ProductRepo(); //Create Products //Console.WriteLine("Creating Product......"); //var newProduct = new Product { Name = "AJs Product", Price = 19.99M, CategoryID = 2, OnSale = 0 }; //repo.CreateProduct(newProduct); //Console.WriteLine("Product Created!"); //Updates Products //Console.WriteLine("Updating Products....."); //var newInfo = new Product { ProductID = 941, StockLevel = 27 }; //repo.UpdateProducts(newInfo); //Console.WriteLine("Product Updated!"); //Delete By ID //var id = 943; //repo.DeleteByID(id); //Delete By Name //var name = "AJs Product"; //repo.DeleteByName(name); //Delete By Name and ProductID ; //repo.DeleteByNameAndID("AJs Product", 945); List <Product> products = repo.GetProducts(); foreach (var prod in products) { Console.WriteLine($"{prod.ProductID} {prod.Name} ------- ${prod.Price}-------You have {prod.StockLevel} of these items."); } Console.ReadLine(); }
static void Main(string[] args) { string defaultKey = File.ReadAllText("appsettings.Debug.Json"); JObject jObject = JObject.Parse(defaultKey); JToken token = jObject["DefaultConnection"]; string connectionString = token.ToString(); ProductRepo.connString = connectionString; ProductRepo repo = new ProductRepo(); //Create Products //Console.WriteLine("Creating Product....."); //var newProduct = new Product //{ // Name = "Jjacksons Product", // Price = 420.69M, // CategoryID = 2, // OnSale = 0 //}; //repo.CreateProduct(newProduct); //Console.WriteLine("Product Created!"); //Update Products //Console.WriteLine("Updating Product...."); //var newInfo = new Product { StockLevel = 27, ProductID = 941 }; //repo.UpdateProduct(newInfo); //Console.WriteLine("Product Updated!"); // DELETE //repo.DeleteProduct(943); //repo.DeleteProduct("Jacksons Product"); //repo.DeleteProduct("Jjacksons Product", 946); // Read Products List <Product> products = repo.GetProducts(); foreach (var prod in products) { Console.WriteLine($"{prod.ProductID} {prod.Name} ----------- ${prod.Price}--------Quantity: {prod.StockLevel} of these items."); } }
static void Main(string[] args) { // setup for hiding your server connection string defaultKey = File.ReadAllText("appsettings.Debug.json"); JObject jObject = JObject.Parse(defaultKey); JToken token = jObject["DefaultConnection"]; string connectionString = token.ToString(); ProductRepo.connString = connectionString; ProductRepo repo = new ProductRepo(); //Create products Console.WriteLine("Creating Product........"); var newProduct = new Product { Name = "Toss Product", Price = 19.99M, CategoryID = 2, OnSale = 0 }; repo.CreateProduct(newProduct); Console.WriteLine("Product Created!"); //Update Products Console.WriteLine("Updating Product....."); var newInfo = new Product { ProductID = 943, StockLevel = 27 }; repo.UpdateProduct(newInfo); //Delete products repo.DeleteProduct(943); repo.DeleteProduct("Ross Product"); repo.DeleteProduct("Toss Product", 946); //Read Products List <Product> products = repo.GetProducts(); foreach (var prod in products) { Console.WriteLine($"{prod.ProductID} {prod.Name} ------ ${prod.Price} ------- stock level is {prod.StockLevel}"); } }