private static void CarTest() { CarManager carManager = new CarManager(new EfCarDal()); // carManager.Add(new Car { BrandId=1, ColorId=2, DailyPrice=1,Description="Dördüncü araba mercedes",ModelYear=2019}); carManager.Delete(new Car { BrandId = 1, ColorId = 2, DailyPrice = 1, Description = "Dördüncü araba mercedes", ModelYear = 2019 }); foreach (var car in carManager.GetCarDetails().Data) { Console.WriteLine(car.Id + " - " + car.BrandName + " - " + car.ColorName + " - " + car.DailyPrice); } }
public bool Delete(Cars car) { try { using (var business = new CarManager()) { business.Delete(car); } return(true); } catch (Exception) { return(false); } }
public ActionResult Delete(int id) { Car car = carManager.Find(x => x.Id == id); if (car.IsActive == false) { reservationManager.Delete(reservationManager.Find(x => x.CarID == id)); reservationManager.Save(); } carManager.Delete(car); carManager.Save(); return(RedirectToAction("Index", "Car")); }
public async void Delete() { string id = "12321dsa1"; List <Car> cars = GetTestCars().ToList(); int count = cars.Count; Mock <ICarAdapter> mock = new Mock <ICarAdapter>(); mock.Setup(adapter => adapter.Delete(id)) .Returns(Task.Run(() => { Car car = cars.FirstOrDefault(c => c.Id.Equals(id)); cars.Remove(car); })); CarManager carManager = new CarManager(mock.Object); await carManager.Delete(id); Assert.NotEqual(count, cars.Count); }
public override void DeleteForm() { Car car; string consoleVal; ConsoleTexts.FrameHeaderFooterLine(); ConsoleTexts.Header(Messages.FormHeaderCarDelete); ConsoleTexts.FrameHeaderFooterLine(); ListAllCars(); if (_carManager.Count().Data > 0) { consoleVal = ConsoleTexts.ConsoleWriteReadLine(Messages.SelectCarIdToDelete); if (consoleVal != "") { car = _carManager.GetById(Convert.ToInt32(consoleVal)).Data; if (ConsoleTexts.ConfirmAction(Messages.DeleteItemAttention)) { _carManager.Delete(car); } } } }
static void Main(string[] args) { CarManager carManager = new CarManager(new EfCarDal()); foreach (var item in carManager.GetAll()) { Console.WriteLine(item.Descriptions); } carManager.Add(new Car { //niye 1002 oluyor ?? BrandId = 2, ColorId = 3, ModelYear = "2011", DailyPrice = 9999, Descriptions = "yeni eklediğim" }); Console.WriteLine("------------------------------"); carManager.Delete(new Car { CarId = 2002,//niye 1002 VB oluyor ?? BrandId = 2, ColorId = 3, ModelYear = "2011", DailyPrice = 9999, Descriptions = "yeni eklediğim" }); Console.WriteLine("---------------------------"); foreach (var item in carManager.GetAll()) { Console.WriteLine(item.Descriptions); } }
private static void CarTest() { CarManager carManager = new CarManager(new EfCarDal()); var cars = carManager.GetAll(); //Tüm liste Console.WriteLine("Start List:"); cars.Data.ForEach(car => Console.WriteLine("Car Id: {0}, Brand Number: {1}, Color Number: {2}," + " Model Year: {3}, Daily Price: {4}, " + "Description: {5}", car.Id, car.BrandId, car.ColorId, car.ModelYear, car.DailyPrice, car.Description)); Console.WriteLine(cars.Message); //Add new car,write new car var operation = carManager.Add(new Car { Id = 5, BrandId = 3, ColorId = 201, ModelYear = 2020, DailyPrice = 1500, Description = "Some car", CarName = "Ford" }); cars = carManager.GetAll(); var newCar = cars.Data.Last(); Console.WriteLine("\n" + "Add new car and write only new car"); Console.WriteLine("Car Id: {0}, Brand Number: {1}, Color Number: {2}, " + "Model Year: {3}, Daily Price: {4}," + " Description: {5}", newCar.Id, newCar.BrandId, newCar.ColorId, newCar.ModelYear, newCar.DailyPrice, newCar.Description); Console.WriteLine(operation.Message); //Delete car by id number operation = carManager.Delete(cars.Data.SingleOrDefault(c => c.Id == 5)); Console.WriteLine("\n" + "Delete Car 5 and write new list"); cars = carManager.GetAll(); cars.Data.ForEach(car => Console.WriteLine("Car Id: {0}, Brand Number: {1}, Color Number: {2}," + " Model Year: {3}, Daily Price: {4}," + " Description: {5}", car.Id, car.BrandId, car.ColorId, car.ModelYear, car.DailyPrice, car.Description)); Console.WriteLine(operation.Message); Console.WriteLine(cars.Message); //get car by id int carID = 4; var getCar = carManager.GetByCarId(carID).Data; Console.WriteLine("\n" + "Get by id"); Console.WriteLine("Car Id: {0}, Brand Number: {1}, Color Number: {2}, " + "Model Year: {3}, Daily Price: {4}," + " Description: {5}", getCar.Id, getCar.BrandId, getCar.ColorId, getCar.ModelYear, getCar.DailyPrice, getCar.Description); Console.WriteLine(carManager.GetByCarId(carID).Message); //update car getCar.ColorId = 101; getCar.Description = "the car"; carManager.Update(getCar); cars = carManager.GetAll(); Console.WriteLine("\n" + "update car 4"); Console.WriteLine("new color: {0} , new description: {1}", getCar.ColorId, getCar.Description); Console.WriteLine(carManager.Update(getCar).Message); //Final version Console.WriteLine("\n" + "Final List:"); cars.Data.ForEach(car => Console.WriteLine("Car Id: {0}, Brand Number: {1}, Color Number: {2}," + " Model Year: {3}, Daily Price: {4}," + " Description: {5}", car.Id, car.BrandId, car.ColorId, car.ModelYear, car.DailyPrice, car.Description)); Console.WriteLine(cars.Message); Console.WriteLine("----"); var BMWCars = carManager.GetCarsByBrandId(1); Console.WriteLine("BMW cars are: "); BMWCars.Data.ForEach(c => Console.WriteLine(c.CarName)); Console.WriteLine(BMWCars.Message); Console.WriteLine("-----"); var whiteCars = carManager.GetCarsByColorId(101); Console.WriteLine("White cars are:"); whiteCars.Data.ForEach(c => Console.WriteLine(c.CarName)); Console.WriteLine(whiteCars.Message); Console.WriteLine("----"); //Addition Error operation = carManager.Add(new Car { Id = 6, BrandId = 2, ColorId = 101, DailyPrice = 0, ModelYear = 2020, CarName = "White mercedes", Description = "Just rent it" }); Console.WriteLine(operation.Message); }
/* There are many main functions at above*/ static void Main(string[] args) { WriteToCenter("'''''''''''''''''''''''''''''''''''''''''''''''"); WriteToCenter("' '"); WriteToCenter("' Software Development Camp '"); WriteToCenter("' '"); WriteToCenter("' Rent A Car System '"); WriteToCenter("' '"); WriteToCenter("'''''''''''''''''''''''''''''''''''''''''''''''"); WriteToCenter("Welcome to Rent A Car system."); WriteToCenter("1) Car Menu 2)Brand Menu 3) Color Menu"); WriteToCenter("Which one do you choose :", true); /* Entities Menu */ string menuId = Console.ReadLine(); switch (menuId) { case "1": //carManager = new CarManager(new EfCarDal()); //Chosen Database Car Manager WriteToCenter("Process Types"); WriteToCenter("1) Add 2) Delete 3) Update 4) List"); WriteToCenter("Which one do you choose :", true); /*Process Types Menu*/ string processId_1 = Console.ReadLine(); switch (processId_1) { case "1": #region Add Data AddCar(); #endregion break; case "2": #region Delete the Car //PrintListToTable(new CarManager(new EfCarDal()).GetAll().Data); WriteToCenter("Enter the Id to be deleted :"); int deletedIndex = Convert.ToInt32(Console.ReadLine()); var process = carManager.Delete(deletedIndex); WriteToCenter(process.IsSuccess is true ? process.Message : ""); #endregion break; case "3": #region Update the Car UpdateCar(); #endregion break; case "4": #region Get Cars //PrintListToTable(new CarManager(new EfCarDal()).GetAll().Data); #endregion break; default: WriteToCenter("Options not found !", true); break; } break; case "2": brandManager = new BrandManager(new EfBrandDal()); // Chosen Database Brand Manager WriteToCenter("Process Types"); WriteToCenter("1) Add 2) Delete 3) Update 4) List"); WriteToCenter("Which one do you choose :", true); /*Process Types Menu*/ string processId_2 = Console.ReadLine(); switch (processId_2) { case "1": #region Add brand AddBrand(); #endregion break; case "2": #region Delete Brand PrintListToTable(new BrandManager(new EfBrandDal()).GetAll().Data); WriteToCenter("Enter the Id to be deleted :"); int deletedIndex = Convert.ToInt32(Console.ReadLine()); var process = brandManager.Delete(deletedIndex); WriteToCenter(process.IsSuccess is true ? process.Message : ""); #endregion break; case "3": #region Update brand UpdateBrand(); #endregion break; case "4": #region Get brands PrintListToTable(new BrandManager(new EfBrandDal()).GetAll().Data); #endregion break; } break; case "3": colorManager = new ColorManager(new EfColorDal()); // Chosen Database Color Manager WriteToCenter("Process Types"); WriteToCenter("1) Add 2) Delete 3) Update 4) List"); WriteToCenter("Which one do you choose :", true); /*Process Types Menu*/ string processId_3 = Console.ReadLine(); switch (processId_3) { case "1": #region Add Color AddColor(); #endregion break; case "2": #region Update Color UpdateColor(); #endregion break; case "3": #region Delete Color PrintListToTable(colorManager.GetAll().Data); WriteToCenter("Enter the Id to be deleted :"); int deletedIndex = Convert.ToInt32(Console.ReadLine()); var process = colorManager.Delete(deletedIndex); WriteToCenter(process.IsSuccess is true ? process.Message : ""); #endregion break; case "4": #region Get Color PrintListToTable(colorManager.GetAll().Data); #endregion break; } break; default: WriteToCenter("Menu not found !", true); break; } Console.ReadLine(); }
private static void Bolum2() { CarManager carManager = new CarManager(new EFCarDal()); BrandManager brandManager = new BrandManager(new EFBrandDal()); ColorManager colorManager = new ColorManager(new EFColorDal()); #region BrandCRUDOperation //Sakın ID yazma.Çünkü primary key ve kendisi otomatik yapıyor! Brand addBrand = new Brand() { BrandName = "Nissan" }; brandManager.Add(addBrand); Brand updateBrand = new Brand() { Id = 1005, BrandName = "Nissanssss" }; brandManager.Update(updateBrand); Brand deleteBrand = new Brand() { Id = 1005, BrandName = "Nissanssss" }; brandManager.Delete(deleteBrand); foreach (var brands in brandManager.GetAll().Data) { Console.WriteLine(brands.BrandName); } #endregion #region ColorCRUDOperation Color addColor = new Color() { ColorName = "Vişne Çürüğü" }; colorManager.Add(addColor); Color updateColor = new Color() { Id = 1002, ColorName = "Elma Kırmızısı" }; colorManager.Update(updateColor); Color deleteColor = new Color() { Id = 1002, ColorName = "Elma Kırmızısı" }; colorManager.Delete(deleteColor); foreach (var color in colorManager.GetAll().Data) { Console.WriteLine(color.ColorName); } #endregion #region CarCRUDOperation Car car1 = new Car() { BrandId = 2, ColorId = 3, DailyPrice = 100, ModelYear = "2006", Descriptions = "Tofaş - Dizel" }; carManager.Add(car1); Car car2 = new Car() { Id = 8, BrandId = 2, ColorId = 3, DailyPrice = 85, ModelYear = "2007", Descriptions = "Renault/Kangoo - Manuel Benzin" }; carManager.Update(car2); Car deleteCar = new Car() { Id = 1002, BrandId = 2, ColorId = 3, DailyPrice = 100, ModelYear = "2006", Descriptions = "Tofaş - Dizel" }; carManager.Delete(deleteCar); var result = carManager.GetAll(); if (result.Success != true) { foreach (var car in result.Data) { Console.WriteLine(car.Descriptions); } } else { Console.WriteLine(result.Message); } #endregion #region DTOUsing DtoUsing(carManager); #endregion }
static void Main(string[] args) { CarManager carManager = new CarManager(new InMemoryCarDal()); foreach (var car in carManager.GetAll()) { Console.WriteLine(car.Id + " " + car.Description); } carManager.Add(new Entities.Concrete.Car { Id = 7, BrandId = 1, ColorId = 2, ModelYear = 2011, DailyPrice = 255, Description = "Range Rover Evoque" }); Console.WriteLine("\n"); foreach (var car in carManager.GetAll()) { Console.WriteLine(car.Id + " " + car.Description); } Console.WriteLine("\n"); Console.WriteLine("1) Range Rover 2) Toyota 3) Ford 4) Mini Cooper"); Console.WriteLine("Enter the number of brand you want to see?"); int choice = Convert.ToInt32(Console.ReadLine()); switch (choice) { case 1: Console.WriteLine("--- Range Rover ---"); foreach (var car in carManager.GetByBrandId(1)) { Console.WriteLine("Model: " + car.Description + " " + "Dailly Price: " + car.DailyPrice); } break; case 2: Console.WriteLine("--- Toyota ---"); foreach (var car in carManager.GetByBrandId(2)) { Console.WriteLine("Model: " + car.Description + " " + "Dailly Price: " + car.DailyPrice); } break; case 3: Console.WriteLine("--- Ford ---"); foreach (var car in carManager.GetByBrandId(3)) { Console.WriteLine("Model: " + car.Description + " " + "Dailly Price: " + car.DailyPrice); } break; case 4: Console.WriteLine("--- mİNİ cooper ---"); foreach (var car in carManager.GetByBrandId(4)) { Console.WriteLine("Model: " + car.Description + " " + "Dailly Price: " + car.DailyPrice); } break; default: Console.WriteLine("ERROR!"); break; } Car car1 = new Car() { Id = 8, BrandId = 1, ColorId = 2, ModelYear = 2011, DailyPrice = 255, Description = "Range Rover Evoque" }; carManager.Add(car1); Console.WriteLine("\n"); foreach (var car in carManager.GetAll()) { Console.WriteLine(car.Id + " " + car.Description); } carManager.Delete(car1); Console.WriteLine("\n"); foreach (var car in carManager.GetAll()) { Console.WriteLine(car.Id + " " + car.Description); } Console.WriteLine("\n"); Console.WriteLine("1) Black Cars 2) Blue Cars 3) White Cars"); Console.WriteLine("Enter the number of color you want to see?"); int choice2 = Convert.ToInt32(Console.ReadLine()); switch (choice2) { case 1: Console.WriteLine("--- Black Cars ---"); foreach (var car in carManager.GetByColorId(1)) { Console.WriteLine("Model: " + car.Description + " " + "Dailly Price: " + car.DailyPrice); } break; case 2: Console.WriteLine("--- Blue Cars ---"); foreach (var car in carManager.GetByColorId(2)) { Console.WriteLine("Model: " + car.Description + " " + "Dailly Price: " + car.DailyPrice); } break; case 3: Console.WriteLine("--- White Cars ---"); foreach (var car in carManager.GetByColorId(3)) { Console.WriteLine("Model: " + car.Description + " " + "Dailly Price: " + car.DailyPrice); } break; default: Console.WriteLine("ERROR!"); break; } }
private static void CarmngOld() { CarManager crmng = new CarManager(new EfCarDAL()); List <Car> cars = crmng.GetAll().Data; foreach (var item in cars) { Console.WriteLine(item.CarId); Console.WriteLine(item.BrandId); Console.WriteLine(item.ColorId); Console.WriteLine(item.DailyPrice); Console.WriteLine(item.ModelYear); Console.WriteLine(item.CarDesc); } string value = "H"; do { Console.WriteLine("Press 1 add Car"); Console.WriteLine("Press 2 delete Car"); Console.WriteLine("Update press 3 "); Console.WriteLine("Press E for exit"); value = Console.ReadLine(); if (value == "1") { Console.WriteLine("(int)(len>2)Id:"); int CarId1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("(int)BrandId:"); int BrandId1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("(int)ColorId:"); int ColorId1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("(int)ModelYear:"); int ModelYear1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("(Decimal)DailyPrice:"); int DailyPrice1 = (int)Convert.ToDecimal(Console.ReadLine()); Console.WriteLine("(string)Desc:"); string CarDesc1 = Console.ReadLine(); Car car1 = new Car(); car1 = new Car() { CarId = CarId1, CarDesc = CarDesc1, BrandId = BrandId1, ColorId = ColorId1, ModelYear = ModelYear1, DailyPrice = DailyPrice1, }; crmng.Add(car1); } else if (value == "2") { Console.WriteLine("(int)(len>2)Id:"); int CarId1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("(int)BrandId:"); int BrandId1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("(int)ColorId:"); int ColorId1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("(int)ModelYear:"); int ModelYear1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("(Decimal)DailyPrice:"); int DailyPrice1 = (int)Convert.ToDecimal(Console.ReadLine()); Console.WriteLine("(string)Desc:"); string CarDesc1 = Console.ReadLine(); Car car1 = new Car(); car1 = new Car() { CarId = CarId1, CarDesc = CarDesc1, BrandId = BrandId1, ColorId = ColorId1, ModelYear = ModelYear1, DailyPrice = DailyPrice1, }; crmng.Delete(car1); } else if (value == "3") { Console.WriteLine("(int)(len>2)Id:"); int CarId1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("(int)BrandId:"); int BrandId1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("(int)ColorId:"); int ColorId1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("(int)ModelYear:"); int ModelYear1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("(Decimal)DailyPrice:"); int DailyPrice1 = (int)Convert.ToDecimal(Console.ReadLine()); Console.WriteLine("(string)Desc:"); string CarDesc1 = Console.ReadLine(); Car car1 = new Car(); car1 = new Car() { CarId = CarId1, CarDesc = CarDesc1, BrandId = BrandId1, ColorId = ColorId1, ModelYear = ModelYear1, DailyPrice = DailyPrice1, }; crmng.Update(car1); } } while (value == "E"); Console.WriteLine("GetByBrandId"); List <Car> GetbyBrandid = crmng.GetCarsByBrandId(2).Data; foreach (var item in GetbyBrandid) { Console.WriteLine(item.CarId); Console.WriteLine(item.BrandId); Console.WriteLine(item.ColorId); Console.WriteLine(item.DailyPrice); Console.WriteLine(item.ModelYear); Console.WriteLine(item.CarDesc); } Console.WriteLine("GetByColorId"); List <Car> GetByColorId = crmng.GetCarsByColorId(2).Data; foreach (var item in GetByColorId) { Console.WriteLine(item.CarId); Console.WriteLine(item.BrandId); Console.WriteLine(item.ColorId); Console.WriteLine(item.DailyPrice); Console.WriteLine(item.ModelYear); Console.WriteLine(item.CarDesc); } }
static void Main(string[] args) { CarManager carManager = new CarManager(new InMemoryCarDal()); List <Car> cars = carManager.GetAll(); Car car1 = new Car { CarId = 7, BrandId = 4, ColorId = 2, DailyPrice = 490, ModelYear = 2014, Description = "Mercedes" }; Car car2 = new Car { CarId = 8, BrandId = 2, ColorId = 3, DailyPrice = 805, ModelYear = 2019, Description = "Lexus" }; //Kayıt Ekleme carManager.Add(car1); carManager.Add(car2); foreach (var car in cars) { Console.WriteLine("Id : " + car.CarId); Console.WriteLine("BrandId: " + car.BrandId); Console.WriteLine("ColorId : " + car.ColorId); Console.WriteLine("DailyPrice : " + car.DailyPrice); Console.WriteLine("ModelYear : " + car.ModelYear); Console.WriteLine("Description : " + car.Description); Console.WriteLine("------------------------------------------"); } //Kayıt Silme //var d= carManager.GetById(4); //carManager.Delete(d); carManager.Delete(car1); foreach (var car in cars) { Console.WriteLine("Id : " + car.CarId); Console.WriteLine("BrandId: " + car.BrandId); Console.WriteLine("ColorId : " + car.ColorId); Console.WriteLine("DailyPrice : " + car.DailyPrice); Console.WriteLine("ModelYear : " + car.ModelYear); Console.WriteLine("Description : " + car.Description); Console.WriteLine("------------------------------------------"); } //Referansta Tutarak Kayıt Güncelleme car2.DailyPrice = 250; carManager.Update(car2); foreach (var car in cars) { Console.WriteLine("Id : " + car.CarId); Console.WriteLine("BrandId: " + car.BrandId); Console.WriteLine("ColorId : " + car.ColorId); Console.WriteLine("DailyPrice : " + car.DailyPrice); Console.WriteLine("ModelYear : " + car.ModelYear); Console.WriteLine("Description : " + car.Description); Console.WriteLine("------------------------------------------"); } Console.ReadKey(); }