/// <summary> /// get a spesific car type acording to a model from the client /// </summary> /// <param name="cartypeModle"></param> /// <returns>a singl car type object</returns> public static CarTypeModel GetSpesificCartype(string cartypeModle) { try { using (CarRentalDbV2Entities db = new CarRentalDbV2Entities()) { CarsTypesTable dbcartype = db.CarsTypesTables.SingleOrDefault(a => a.Model == cartypeModle); if (dbcartype == null) { return(null); } return(new CarTypeModel { CostPerDay = dbcartype.CostPerDay, FinePrice = dbcartype.FinePrice, Model = dbcartype.Model, IsAutomatic = dbcartype.IsAutomatic, Manufacturer = dbcartype.Manufacturer, Year = dbcartype.Year }); } } catch { return(null); } }
/// <summary> /// Add a new car type to the DB /// </summary> /// <param name="NewCartype">an car type object conatains all the car type data</param> /// <returns>true if the actions secseed false if it didnt</returns> public static bool AddNewCartype(CarTypeModel NewCartype) { try { using (CarRentalDbV2Entities db = new CarRentalDbV2Entities()) { CarsTypesTable dbCarType = new CarsTypesTable { Model = NewCartype.Model, IsAutomatic = NewCartype.IsAutomatic, CostPerDay = NewCartype.CostPerDay, Year = NewCartype.Year, Manufacturer = NewCartype.Manufacturer, FinePrice = NewCartype.FinePrice, }; db.CarsTypesTables.Add(dbCarType); db.SaveChanges(); return(true); } } catch { return(false); } }
/// <summary> /// edit a car type info /// </summary> /// <param name="cartypeModle">the car type model from the user--string</param> /// <param name="cartypeparam">an car type object contain all of the car type info</param> /// <returns>true if the actions secseed false if it didnt</returns> public static bool EditCarType(string cartypeModle, CarTypeModel cartypeparam) { try { using (CarRentalDbV2Entities db = new CarRentalDbV2Entities()) { CarsTypesTable dbcartype = db.CarsTypesTables.SingleOrDefault(a => a.Model == cartypeModle); if (dbcartype == null) { return(false); } dbcartype.Model = cartypeparam.Model; dbcartype.Year = cartypeparam.Year; dbcartype.CostPerDay = cartypeparam.CostPerDay; dbcartype.FinePrice = cartypeparam.FinePrice; dbcartype.Manufacturer = cartypeparam.Manufacturer; dbcartype.IsAutomatic = cartypeparam.IsAutomatic; db.SaveChanges(); return(true); } } catch { return(false); } }
/// <summary> /// add a new car to the db /// </summary> /// <param name="NewCar">the car modle object</param> /// <returns> true if the action sucseed false if it didnt</returns> public static bool AddNewCar(CarModel NewCar) { try { using (CarRentalDbV2Entities db = new CarRentalDbV2Entities()) { BranchesTable dbBrance = db.BranchesTables.FirstOrDefault(a => a.BranceName == NewCar.CarLocation.BranceName); CarsTypesTable dbCarType = db.CarsTypesTables.FirstOrDefault(a => a.Model == NewCar.CarType.Model); if (dbBrance == null || dbCarType == null) { return(false); } CarsTable NewdbCar = new CarsTable { CarLocation = dbBrance.ID, CarType = dbCarType.ID, CarKilometer = NewCar.CarKilometer, CarImg = NewCar.CarImg, CarStatus = NewCar.CarStatus, CarlicenseNumber = NewCar.CarlicenseNumber, }; db.CarsTables.Add(NewdbCar); db.SaveChanges(); return(true); } } catch { return(false); } }
/// <summary> /// edit a car info in the db /// </summary> /// <param name="Carlicenceparam">the car licence number</param> /// <param name="carparam">a car modle contains all the car data</param> /// <returns>true if the actions sucseed false if it didnt</returns> public static bool EditCar(string Carlicenceparam, CarModel carparam) { try { using (CarRentalDbV2Entities db = new CarRentalDbV2Entities()) { CarsTable dbcar = db.CarsTables.SingleOrDefault(a => a.CarlicenseNumber == Carlicenceparam); CarsTypesTable dbcarType = db.CarsTypesTables.SingleOrDefault(a => a.Model == carparam.CarType.Model); BranchesTable dbBrance = db.BranchesTables.SingleOrDefault(a => a.BranceName == carparam.CarLocation.BranceName); if (dbcar == null || dbcarType == null || dbBrance == null) { return(false); } dbcar.CarImg = carparam.CarImg; dbcar.CarLocation = dbBrance.ID; dbcar.CarKilometer = carparam.CarKilometer; dbcar.CarlicenseNumber = carparam.CarlicenseNumber; dbcar.CarStatus = carparam.CarStatus; dbcar.CarType = dbcarType.ID; db.SaveChanges(); return(true); } } catch { return(false); } }
/// <summary> /// delete a cartype from the db /// </summary> /// <param name="cartypeModle">the cartype model </param> /// <returns>true if the actions secseed false if it didnt</returns> public static bool DeleteCartype(string cartypeModle) { try { using (CarRentalDbV2Entities db = new CarRentalDbV2Entities()) { CarsTypesTable dbcartype = db.CarsTypesTables.SingleOrDefault(a => a.Model == cartypeModle); if (dbcartype == null) { return(false); } db.CarsTypesTables.Remove(dbcartype); db.SaveChanges(); return(true); } } catch { return(false); } }