private static void CarManager(Car car1) { CarManager carManager = new CarManager(new EfCarDal()); // Tüm araba listesini yazdırıyoruz. foreach (var car in carManager.GetAll()) { System.Console.WriteLine(car.CarId + " nolu araba " + car.CarModelYear + " model ve " + car.CarDescription); } // Arabanın Description'ı 2 Harften Eşit veya Fazlayse ve DailyPrice'ı 0 dan Büyükse Database'e ekleme işlemi yapıyoruz. if (car1.CarDescription.Length >= 2 && car1.CarDailyPrice > 0) { // Araba listesine yen bir araba ekliyoruz. carManager.Add(car1); } // Eklediğimiz arabayı listeden kaldırıyoruz. //carManager.Delete(car1); System.Console.WriteLine("**********************\nEklenen Arabanın Özellikleri ;"); BrandManager brandManager = new BrandManager(new EfBrandDal()); // Databese'e Araba Eklerken İlk Değer Olarak CarId Atayamadığımızdan Dolayı Manuel Olarak Kendimiz Atıyoruz. car1.CarId = 8; // Tüm Araba Listesinden CarId'si 8 Olan Arabanın Verilerini Yazdırıyoruz. foreach (var car in carManager.GetAll()) { if (car.CarId == car1.CarId) { System.Console.WriteLine(car.CarId + " nolu araba " + car.CarModelYear + " model ve " + car.CarDescription + " kiralık."); } } // Aynı Araba İçin Marka Bilgisini Getiriyoruz. foreach (var car in brandManager.GetByBrandId(car1.BrandId)) { System.Console.WriteLine("Markası : " + car.BrandName); } ColorManager colorManager = new ColorManager(new EfColorDal()); // Aynı Araba İçin Renk Bilgisini Getiriyoruz. foreach (var car in colorManager.GetByColorId(car1.ColorId)) { System.Console.WriteLine("Rengi : " + car.ColorName); } System.Console.WriteLine("**********************"); // Tüm Bu İşlemlerden Sonra Araba Listesini Tekrardan Yazdırıyoruz. foreach (var car in carManager.GetAll()) { System.Console.WriteLine(car.CarId + " nolu araba " + car.CarModelYear + " model ve " + car.CarDescription); } }
static void Main(string[] args) { CarManager carManager = new CarManager(new EfCarDal()); IResult deneme = carManager.Add(new Car { BrandId = 2, ColorId = 1, DailyPrice = 2, Description = "carsamba dersi denemesi", ModelYear = 3999 });; System.Console.WriteLine(deneme.Message); foreach (var car in carManager.GetCarDetailsByColor().Data) { System.Console.WriteLine("{0} {1} {2} {3}", car.BrandName, car.CarDetails, car.ColorName, car.DailyPrice); } }
private static void AddCarTest() { CarManager cars = new CarManager(new EfCarDal()); var result = cars.Add(new Car { BrandId = 3, ColorId = 2, DailyPrice = 300, ModelYear = 2004 }); if (result.Success == true) { System.Console.WriteLine(result.Message); } else { System.Console.WriteLine(result.Message); } }
private static void CarTest() { CarManager carManager = new CarManager(new EfCarDal()); System.Console.WriteLine("GetAll:"); foreach (var car in carManager.GetAll()) { System.Console.WriteLine(car.ModelYear + " - " + car.Description); } System.Console.WriteLine("Add:"); var carNew = new Car { Id = 6, BrandId = 2, ColorId = 2, DailyPrice = 600, Description = "X5 XDRIVE", ModelYear = 2020 }; carManager.Add(carNew); System.Console.WriteLine(carNew.ModelYear + " - " + carNew.Description + " eklendi."); System.Console.WriteLine("GetAll:"); foreach (var car in carManager.GetAll()) { System.Console.WriteLine(car.ModelYear + " - " + car.Description); } System.Console.WriteLine("Update:"); carNew.Description = "X5 XDRIVE DIESEL"; carManager.Update(carNew); System.Console.WriteLine(carNew.ModelYear + " - " + carNew.Description + " güncellendi."); System.Console.WriteLine("GetAll:"); foreach (var car in carManager.GetAll()) { System.Console.WriteLine(car.ModelYear + " - " + car.Description); } System.Console.WriteLine("Delete:"); carManager.Delete(carNew); System.Console.WriteLine(carNew.ModelYear + " - " + carNew.Description + " silindi."); System.Console.WriteLine("GetAll:"); foreach (var car in carManager.GetAll()) { System.Console.WriteLine(car.ModelYear + " - " + car.Description); } }
private static CarManager CarAdd() { CarManager carManager = new CarManager(new EfCarDal()); var result = carManager.Add(new Car { BrandId = 2, ColorId = 3, DailyPrice = 1000, ModelYear = "2021", Descriptions = "Mercedes Benz Full" }); System.Console.WriteLine(result.Message); return(carManager); //var result = carManager.GetAll(); //foreach (var car in result.Data) //{ // System.Console.WriteLine(car.Descriptions); //} }
/////////////////////////////////////// private static void ThirdHW(CarManager carManager, ColorManager colorManager, BrandManager brandManager) { Dictionary <int, string> colors = new Dictionary <int, string>() { [1] = "Mavi", [2] = "Kırmızı", [3] = "Siyah", [4] = "Turuncu", [5] = "Beyaz", }; foreach (var color in colors) { colorManager.Add(new Color { Id = color.Key, Name = color.Value }); } colorManager.GetAll(); /////////////////////////////// Dictionary <int, string> brands = new Dictionary <int, string>() { [1] = "BMW", [2] = "Mercedes", [3] = "Toyoto", [4] = "Tofaş", [5] = "Audi", }; foreach (var brand in brands) { brandManager.Add(new Brand { Id = brand.Key, Name = brand.Value }); } /////////////////////////////// carManager.Add(new Car { Id = 1, BrandId = 1, ColorId = 3, CarName = "BMW", ModelYear = 2010, DailyPrice = 1000 }); carManager.Add(new Car { Id = 2, BrandId = 2, ColorId = 3, CarName = "Mercedes", ModelYear = 2014, DailyPrice = 1500 }); /////////////////////////////// // carManager.Update(new Car { Id = 2, BrandId = 2, ColorId = 2, CarName = "Mercedes", DailyPrice = 2000, ModelYear = 2014 }); // System.Console.WriteLine("-------------GetAll----------"); // foreach (var car in carManager.GetAll()) // { // System.Console.WriteLine(car.CarName); // } // System.Console.WriteLine("-------------------------------------------"); // brandManager.Delete(new Brand { Id = 4 }); // System.Console.WriteLine("-------------GetAllBrands----------"); // foreach (var brand in brandManager.GetAll()) // { // System.Console.WriteLine(brand.Name); // } // System.Console.WriteLine("-------------------------------------------"); // System.Console.WriteLine("-------------GetCarDetails----------"); // foreach (var car in carManager.GetCarDetails()) // { // System.Console.WriteLine("Araba ismi: {0}, Markası: {1}, Rengi: {2}, Günlük Ücreti: {3}", car.CarName, car.BrandName, car.ColorName, car.DailyPrice); // } //} //private static void SecondHW(CarManager carManager) //{ // // Hata Mesajı Verir. // carManager.Add(new Car // { // BrandId = 2, // ColorId = 3, // CarName = "W", // ModelYear = 2010, // DailyPrice = 1000, // }); // // Başarılı bir şekilde ekleme yapar. // carManager.Add(new Car // { // BrandId = 2, // ColorId = 3, // CarName = "BMW", // ModelYear = 2010, // DailyPrice = 1000, // }); // foreach (var car in carManager.GetAll()) // { // System.Console.WriteLine(car.CarName); // } // System.Console.WriteLine("------------------"); //} //private static void FirstHW(CarManager carManager) //{ // foreach (var car in carManager.GetAll()) // { // System.Console.WriteLine("Araba ID: " + car.Id + " " + // "Araba Modeli: " + car.Description + " " + // "Araba Marka ID: " + car.BrandId + " " + // "Araba Renk ID: " + car.ColorId + " " + // "Araba Günlük Ücreti: " + car.DailyPrice); // } // System.Console.WriteLine("-----------------------\n"); // System.Console.WriteLine("Get By ID"); // System.Console.WriteLine("------------"); // foreach (var car1 in carManager.GetById(2)) // { // System.Console.WriteLine("Araba ID: " + car1.Id + " " + "Araba Modeli: " + car1.Description); // } // for (int ID = 1; ID <= carManager.GetAll().Count; ID++) // { // foreach (var car1 in carManager.GetById(ID)) // { // System.Console.WriteLine("Araba ID: " + car1.Id + " " + "Araba Modeli: " + car1.Description); // } // } //} }
static void Main(string[] args) { bool loop = true; CarManager carManager = new CarManager(new InMemoryCarDal()); while (loop) { System.Console.WriteLine("1. List the Cars \t 2. List by Brand Id \t 3. Add a Car \t 4. Delete a Car \t 5. Update a Car \t 6. Exit"); System.Console.WriteLine("\nChoice: "); int choice = Convert.ToInt32(System.Console.ReadLine()); switch (choice) { case 1: foreach (var car in carManager.GetAll()) { System.Console.WriteLine("---- CAR ----"); System.Console.WriteLine("Car ID: " + car.Id); System.Console.WriteLine("Brand ID: " + car.BrandId); System.Console.WriteLine("Year: " + car.ModelYear); System.Console.WriteLine("Daily Price: " + car.DailyPrice); System.Console.WriteLine("Description: " + car.Description); System.Console.WriteLine("------------\n"); } break; case 2: System.Console.WriteLine("Insert the brand ID"); int Id = Convert.ToInt32(System.Console.ReadLine()); foreach (var car in carManager.GetById(Id)) { System.Console.WriteLine("---- CAR ----"); System.Console.WriteLine("Car ID: " + car.Id); System.Console.WriteLine("Brand ID: " + car.BrandId); System.Console.WriteLine("Year: " + car.ModelYear); System.Console.WriteLine("Daily Price: " + car.DailyPrice); System.Console.WriteLine("Description: " + car.Description); System.Console.WriteLine("------------\n"); } break; case 3: System.Console.WriteLine("Insert the car ID: "); int id = Convert.ToInt32(System.Console.ReadLine()); System.Console.WriteLine("Insert the brand ID: "); int brandId = Convert.ToInt32(System.Console.ReadLine()); System.Console.WriteLine("Insert the year: "); int year = Convert.ToInt32(System.Console.ReadLine()); System.Console.WriteLine("Insert the daily price: "); decimal price = Convert.ToDecimal(System.Console.ReadLine()); System.Console.WriteLine("Insert a description for car: "); string desc = System.Console.ReadLine(); Car addedCar = new Car { Id = id, BrandId = brandId, ModelYear = year, DailyPrice = price, Description = desc }; carManager.Add(addedCar); System.Console.WriteLine("Car added successfully.\n"); break; case 4: System.Console.WriteLine("Insert the car ID for deletion process: "); id = Convert.ToInt32(System.Console.ReadLine()); Car deletedCar = new Car(); foreach (var car in carManager.GetAll()) { if (car.Id == id) { deletedCar = car; } } carManager.Delete(deletedCar); System.Console.WriteLine("Car deleted successfully."); break; case 5: System.Console.WriteLine("Insert the existing car ID: "); id = Convert.ToInt32(System.Console.ReadLine()); System.Console.WriteLine("Insert the brand ID: "); brandId = Convert.ToInt32(System.Console.ReadLine()); System.Console.WriteLine("Insert the year: "); year = Convert.ToInt32(System.Console.ReadLine()); System.Console.WriteLine("Insert the daily price: "); price = Convert.ToDecimal(System.Console.ReadLine()); System.Console.WriteLine("Insert a description for car: "); desc = System.Console.ReadLine(); Car updatedCar = new Car { Id = id, BrandId = brandId, ModelYear = year, DailyPrice = price, Description = desc }; carManager.Update(updatedCar); System.Console.WriteLine("Car updated successfully."); break; case 6: loop = false; break; default: System.Console.WriteLine("You inserted wrong choice number."); break; } } }