public static string AddCarTypeTo_db(BOLCarType carType) { try { CarsType isExist = ValidateCarInput.IsExist(carType); if (isExist == null) { using (RentalcarsEntities1 ef = new RentalcarsEntities1()) { ef.CarsTypes.Add(new CarsType { ManufacturerName = carType.ManufacturerName, Model = carType.Model, DailyCost = carType.DailyCost, CostDayOverdue = carType.CostDayOverdue, ManufactureYear = carType.ManufactureYear, Gear = carType.Gear }); ef.SaveChanges(); return("OK"); } } else { throw new InvalidOperationException($"this car type is already exist please change the values and try again"); } } catch { return("this car type is already exist please change the values and try again"); } }
public static string UpDataCarTypeTo_db(BOLCarType oldCarType, BOLCarType newCarType) { CarsType isExist = ValidateCarInput.IsExist(oldCarType); try { if (isExist != null) { using (RentalcarsEntities1 ef = new RentalcarsEntities1()) { CarsType isTheNewExist = ValidateCarInput.IsExist(newCarType); if (isTheNewExist == null) { CarsType dbUser = ef.CarsTypes.FirstOrDefault(u => u.CarTypeID == isExist.CarTypeID); dbUser.ManufacturerName = newCarType.ManufacturerName; dbUser.Model = newCarType.Model; dbUser.DailyCost = newCarType.DailyCost; dbUser.ManufactureYear = newCarType.ManufactureYear; dbUser.Gear = newCarType.Gear; ef.SaveChanges(); return("Ok"); } else { return("this car type is already exist please change the values and try again"); } } } else { throw new InvalidOperationException($"this car type is not exist please change the values and try again"); } } catch { return("this car type is not exist please change the values and try again"); } }