static void DeleteEntry(DefaultContainer container) { string userInput = " "; int cleanInput = 0; Console.WriteLine($"Give the ID of the car you wish to remove \n"); userInput = Console.ReadLine(); while (!int.TryParse(userInput, out cleanInput)) { Console.Write("This is not valid input. Please enter an integer value: \n"); userInput = Console.ReadLine(); } foreach (var p in container.Cars) { if (p.ID == cleanInput) { container.DeleteObject(p); //container.UpdateObject(p); var serviceResponse = container.SaveChanges(); foreach (var operationResponse in serviceResponse) { Console.WriteLine("Response: {0}", operationResponse.StatusCode); } } } Console.WriteLine($"Your result: removed a car \n"); }
//Adds a new car to the list of cars static void AddCar(DefaultContainer container) { bool answer = false; string input1 = ""; string colour = ""; int cleanNum1 = 0; int iD = 0; _Brands brand = _Brands.Audi; var p = new Car(); Console.Write("Type the number of cars made, and then press Enter: \n"); input1 = Console.ReadLine(); while (!int.TryParse(input1, out cleanNum1)) { Console.Write("This is not valid input. Please enter an integer value: \n"); input1 = Console.ReadLine(); } Console.Write("Type the color of the car, and then press Enter: \n"); colour = Console.ReadLine(); Console.Write("Is the car APK certifeid? Type true or false, and then press Enter: \n"); input1 = Console.ReadLine().ToLower(); iD = GetCorrectID(container); if (string.Equals(input1, "true")) { answer = true; } brand = SetBrand(); p.ID = iD; p.AmountMade = cleanNum1; p.Brand = brand; p.Colour = colour; p.TimeWhenAddedToDatabase = DateTime.Now; p.APK = answer; container.AddObject("cars", p); var serviceResponse = container.SaveChanges(); foreach (var operationResponse in serviceResponse) { Console.WriteLine("Response: {0}", operationResponse.StatusCode); } Console.WriteLine($"Your result: Added a car"); }
static void ChangeEntry(DefaultContainer container) { string userInput = " "; int cleanInput = 0; Console.WriteLine($"Give the ID of the car you wish to change \n"); userInput = Console.ReadLine(); while (!int.TryParse(userInput, out cleanInput)) { Console.Write("This is not valid input. Please enter an integer value: \n"); userInput = Console.ReadLine(); } foreach (var p in container.Cars) { if (p.ID == cleanInput) { bool answer = false; string input1 = ""; string colour = ""; int cleanNum1 = 0; Console.Write("Type the number of cars made, and then press Enter: \n"); input1 = Console.ReadLine(); while (!int.TryParse(input1, out cleanNum1)) { Console.Write("This is not valid input. Please enter an integer value: \n"); input1 = Console.ReadLine(); } Console.Write("Type the color of the car, and then press Enter: \n"); colour = Console.ReadLine(); Console.Write("Is the car APK certifeid? Type true or false, and then press Enter: \n"); input1 = Console.ReadLine().ToLower(); if (string.Equals(input1, "true")) { answer = true; } p.AmountMade = cleanNum1; p.Brand = SetBrand(); p.Colour = colour; p.APK = answer; p.TimeWhenAddedToDatabase = DateTime.Now; container.UpdateObject(p); var serviceResponse = container.SaveChanges(); foreach (var operationResponse in serviceResponse) { Console.WriteLine("Response: {0}", operationResponse.StatusCode); } } } Console.WriteLine($"Your result: Changed a car \n"); }