/// <summary> /// UpdateAuthorByName updates a specific Author from the DB by the EF ref /// by the `authorName` parameter /// and returns bool value - if the action was success /// </summary> static public bool UpdateCarTypeByModel(string carModel, CarTypeModel newCarType) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { CarType selectedCarType = ef.CarTypes.FirstOrDefault(dbCarType => dbCarType.model == carModel); if (selectedCarType == null) { return(false); } // selectedCarType.carTypeId = newCarType.CarTypeId; selectedCarType.manufacturer = newCarType.Manufacturer; selectedCarType.model = newCarType.Model; selectedCarType.dailyCost = newCarType.DailyCost; selectedCarType.dayDelayCost = newCarType.DayDelayCost; selectedCarType.manufactureYear = newCarType.ManufactureYear; selectedCarType.gear = newCarType.Gear; ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// UpdateAuthorByName updates a specific Author from the DB by the EF ref /// by the `authorName` parameter /// and returns bool value - if the action was success /// </summary> static public bool UpdateUserByName(string userName, UserModel newUser) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { User selectedUser = ef.Users.FirstOrDefault(dbUser => dbUser.userName == userName); if (selectedUser == null) { return(false); } selectedUser.userName = newUser.UserName; selectedUser.fullName = newUser.UserFullName; selectedUser.identityNumber = newUser.UserIdentityNumber; selectedUser.birthDay = newUser.UserBirthDay; selectedUser.gender = newUser.UserGender; selectedUser.email = newUser.UserEmail; selectedUser.password = newUser.UserPassword; selectedUser.userRole = newUser.UserRole; selectedUser.image = newUser.UserImage; ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// SelectAuthorByName selects a specific Author from the DB by the EF ref /// by the `authorName` parameter /// and maps the DAL object to BOL object /// </summary> static public CarTypeModel SelectCarTypeByModel(string carModel) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { CarType selectedCarType = ef.CarTypes.FirstOrDefault(dbCarType => dbCarType.model == carModel); if (selectedCarType == null) { return(null); } return(new CarTypeModel { // CarTypeId = selectedCarType.carTypeId, Manufacturer = selectedCarType.manufacturer, Model = selectedCarType.model, DailyCost = selectedCarType.dailyCost, DayDelayCost = selectedCarType.dayDelayCost, ManufactureYear = selectedCarType.manufactureYear, Gear = selectedCarType.gear, }); } } catch (Exception) { return(null); } }
/// <summary> /// InsertAuthor inserts a new Author to the DB by the EF ref /// maps the `newAuthor` parameter (BOL object) to a `Author` (DAL object) /// and returns bool value - if the action was success /// </summary> static public bool InsertCarType(CarTypeModel newCarType) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { CarType newDbCarType = new CarType { manufacturer = newCarType.Manufacturer, model = newCarType.Model, dailyCost = newCarType.DailyCost, dayDelayCost = newCarType.DayDelayCost, manufactureYear = newCarType.ManufactureYear, gear = newCarType.Gear, }; ef.CarTypes.Add(newDbCarType); ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// SelectAuthorByName selects a specific Author from the DB by the EF ref /// by the `authorName` parameter /// and maps the DAL object to BOL object /// </summary> static public UserModel SelectUserByName(string userName) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { User selectedUser = ef.Users.FirstOrDefault(dbUser => dbUser.userName == userName); if (selectedUser == null) { return(null); } return(new UserModel { UserName = selectedUser.userName, UserFullName = selectedUser.fullName, UserIdentityNumber = selectedUser.identityNumber, UserBirthDay = selectedUser.birthDay, UserGender = selectedUser.gender, UserEmail = selectedUser.email, UserPassword = selectedUser.password, UserRole = selectedUser.userRole, UserImage = selectedUser.image, }); } } catch (Exception) { return(null); } }
/// <summary> /// UpdateAuthorByName updates a specific Author from the DB by the EF ref /// by the `authorName` parameter /// and returns bool value - if the action was success /// </summary> static public bool UpdateBranchByName(string branchName, BranchModel newBranch) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { Branch selectedBranch = ef.Branches.FirstOrDefault(dbBranch => dbBranch.branchName == branchName); if (selectedBranch == null) { return(false); } selectedBranch.address = newBranch.BranchAddress; selectedBranch.latitude = newBranch.BranchLatitude; selectedBranch.longitude = newBranch.BranchLongitude; selectedBranch.branchName = newBranch.BranchName; ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// SelectAllAuthors reads all the Authors from the DB by the EF ref /// and maps the DAL objects to BOL objects /// </summary> static public UserModel[] SelectAllUsers() { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { return(ef.Users.Select(dbUser => new UserModel { UserName = dbUser.userName, UserFullName = dbUser.fullName, UserIdentityNumber = dbUser.identityNumber, UserBirthDay = dbUser.birthDay, UserGender = dbUser.gender, UserEmail = dbUser.email, UserPassword = dbUser.password, UserRole = dbUser.userRole, UserImage = dbUser.image, }).ToArray()); } } catch (Exception) { return(null); } }
/// <summary> /// SelectAuthorByName selects a specific Author from the DB by the EF ref /// by the `authorName` parameter /// and maps the DAL object to BOL object /// </summary> static public BranchModel SelectBranchByName(string branchName) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { Branch selectedBranch = ef.Branches.FirstOrDefault(dbUser => dbUser.branchName == branchName); if (selectedBranch == null) { return(null); } return(new BranchModel { BranchAddress = selectedBranch.address, BranchLatitude = selectedBranch.latitude, BranchLongitude = selectedBranch.longitude, BranchName = selectedBranch.branchName, }); } } catch (Exception) { return(null); } }
/// <summary> /// UpdateBookByName updates a specific Book from the DB by the EF ref /// by the `bookName` parameter /// and returns bool value - if the action was success /// </summary> static public bool UpdateCarByCarNumber(string carNumber, CarModel newCar) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { Car selectedCar = ef.Cars.FirstOrDefault(dbCar => dbCar.carNumber == carNumber); if (selectedCar == null) { return(false); } selectedCar.carNumber = newCar.CarNumber; selectedCar.currentKilometerage = newCar.CarCurrentKilometerage; selectedCar.image = newCar.CarImage; selectedCar.isFitForRental = newCar.CarIsFitForRental; ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// UpdateBookByName updates a specific Book from the DB by the EF ref /// by the `bookName` parameter /// and returns bool value - if the action was success /// </summary> static public bool UpdateOrderByCarNumber(string carNumber, OrderModel newOrder) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { Order selectedOrder = ef.Orders.FirstOrDefault(dbOrder => dbOrder.Car.carNumber == carNumber); if (selectedOrder == null) { return(false); } selectedOrder.startDate = newOrder.OrderStartDate; selectedOrder.returnDate = newOrder.OrderReturnDate; selectedOrder.actualReturnDate = newOrder.OrderActualReturnDate; ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// InsertAuthor inserts a new Author to the DB by the EF ref /// maps the `newAuthor` parameter (BOL object) to a `Author` (DAL object) /// and returns bool value - if the action was success /// </summary> static public bool InsertUser(UserModel newUser) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { User newDbUser = new User { userName = newUser.UserName, fullName = newUser.UserFullName, identityNumber = newUser.UserIdentityNumber, birthDay = newUser.UserBirthDay, gender = newUser.UserGender, email = newUser.UserPassword, userRole = newUser.UserRole, password = newUser.UserPassword, image = newUser.UserImage, }; ef.Users.Add(newDbUser); ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// SelectAllBooks reads all the Books from the DB by the EF ref /// and maps the DAL objects to BOL objects /// </summary> static public OrderModel[] SelectAllOrders() { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { return(ef.Orders.Select(dbOrder => new OrderModel { OrderStartDate = dbOrder.startDate, OrderReturnDate = dbOrder.returnDate, OrderActualReturnDate = dbOrder.actualReturnDate, OrderCar = new CarModel { CarNumber = dbOrder.Car.carNumber, CarCurrentKilometerage = dbOrder.Car.currentKilometerage, CarIsFitForRental = dbOrder.Car.isFitForRental, CarImage = dbOrder.Car.image, CarType = new CarTypeModel { // CarTypeId = dbCar.CarType.carTypeId, DailyCost = dbOrder.Car.CarType.dailyCost, DayDelayCost = dbOrder.Car.CarType.dayDelayCost, Gear = dbOrder.Car.CarType.gear, Manufacturer = dbOrder.Car.CarType.manufacturer, ManufactureYear = dbOrder.Car.CarType.manufactureYear, Model = dbOrder.Car.CarType.model, }, CarBranch = new BranchModel { BranchAddress = dbOrder.Car.Branch.address, BranchLatitude = dbOrder.Car.Branch.latitude, BranchLongitude = dbOrder.Car.Branch.longitude, BranchName = dbOrder.Car.Branch.branchName, }, }, OrderUser = new UserModel { UserName = dbOrder.User.userName, UserIdentityNumber = dbOrder.User.identityNumber, UserFullName = dbOrder.User.fullName, UserPassword = dbOrder.User.password, UserGender = dbOrder.User.gender, UserEmail = dbOrder.User.email, UserBirthDay = dbOrder.User.birthDay, UserImage = dbOrder.User.image, UserRole = dbOrder.User.userRole, } }).ToArray()); } } catch (Exception) { return(null); } }
/// <summary> /// SelectBookByName selects a specific Book from the DB by the EF ref /// by the `bookName` parameter /// and maps the DAL object to BOL object /// </summary> static public CarModel SelectCarByCarNumber(string carNumber) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { Car selectedCar = ef.Cars.FirstOrDefault(dbCar => dbCar.carNumber == carNumber); if (selectedCar == null) { return(null); } return(new CarModel { CarCurrentKilometerage = selectedCar.currentKilometerage, CarImage = selectedCar.image, CarIsFitForRental = selectedCar.isFitForRental, CarNumber = selectedCar.carNumber, CarBranch = new BranchModel { BranchAddress = selectedCar.Branch.address, BranchLatitude = selectedCar.Branch.latitude, BranchLongitude = selectedCar.Branch.longitude, BranchName = selectedCar.Branch.branchName, }, CarType = new CarTypeModel { // CarTypeId = selectedCar.CarType.carTypeId, DailyCost = selectedCar.CarType.dailyCost, DayDelayCost = selectedCar.CarType.dayDelayCost, Gear = selectedCar.CarType.gear, Manufacturer = selectedCar.CarType.manufacturer, ManufactureYear = selectedCar.CarType.manufactureYear, Model = selectedCar.CarType.model, } }); } } catch (Exception) { return(null); } }
/// <summary> /// SelectAllAuthors reads all the Authors from the DB by the EF ref /// and maps the DAL objects to BOL objects /// </summary> static public BranchModel[] SelectAllBranches() { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { return(ef.Branches.Select(dbBranch => new BranchModel { BranchAddress = dbBranch.address, BranchLatitude = dbBranch.latitude, BranchLongitude = dbBranch.longitude, BranchName = dbBranch.branchName, }).ToArray()); } } catch (Exception) { return(null); } }
/// <summary> /// UpdateBookByName updates a specific Book from the DB by the EF ref /// by the `bookName` parameter /// and returns bool value - if the action was success /// </summary> static public bool UpdateCarByCarNumber(string carNumber, CarModel newCar) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { Branch selectedBranch = ef.Branches.FirstOrDefault(dbBranch => dbBranch.branchName == newCar.CarBranch.BranchName); if (selectedBranch == null) { return(false); } CarType selectedCarType = ef.CarTypes.FirstOrDefault(dbCarType => dbCarType.model == newCar.CarType.Model); if (selectedCarType == null) { return(false); } Car selectedCar = ef.Cars.FirstOrDefault(dbCar => dbCar.carNumber == carNumber); if (selectedCar == null) { return(false); } selectedCar.carNumber = newCar.CarNumber; selectedCar.currentKilometerage = newCar.CarCurrentKilometerage; selectedCar.image = newCar.CarImage; selectedCar.isFitForRental = newCar.CarIsFitForRental; selectedCar.branchId = selectedBranch.BranchId; selectedCar.carTypeId = selectedCarType.carTypeId; ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// DeleteAuthorByName delete a specific Author from the DB by the EF ref /// by the `authorName` parameter /// and returns bool value - if the action was success /// </summary> static public bool DeleteCarTypeByModel(string carModel) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { CarType selectedCarType = ef.CarTypes.FirstOrDefault(dbCarType => dbCarType.model == carModel); if (selectedCarType == null) { return(false); } ef.CarTypes.Remove(selectedCarType); ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// DeleteAuthorByName delete a specific Author from the DB by the EF ref /// by the `authorName` parameter /// and returns bool value - if the action was success /// </summary> static public bool DeleteBranchByName(string branchName) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { Branch selectedBranch = ef.Branches.FirstOrDefault(dbBranch => dbBranch.branchName == branchName); if (selectedBranch == null) { return(false); } ef.Branches.Remove(selectedBranch); ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// DeleteBookByName deletes a specific Book from the DB by the EF ref /// by the `bookName` parameter /// and returns bool value - if the action was success /// </summary> static public bool DeleteOrderByCarNumber(string carNumber) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { Order selectedOrder = ef.Orders.FirstOrDefault(dbOrder => dbOrder.Car.carNumber == carNumber); if (selectedOrder == null) { return(false); } ef.Orders.Remove(selectedOrder); ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// DeleteAuthorByName delete a specific Author from the DB by the EF ref /// by the `authorName` parameter /// and returns bool value - if the action was success /// </summary> static public bool DeleteUserByName(string userName) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { User selectedUser = ef.Users.FirstOrDefault(dbUser => dbUser.userName == userName); if (selectedUser == null) { return(false); } ef.Users.Remove(selectedUser); ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// InsertBook inserts a new Book to the DB by the EF ref /// maps the `newBook` parameter (BOL object) to a `Book` (DAL object) /// and returns bool value - if the action was success /// </summary> static public bool InsertCar(CarModel newCar) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { Branch selectedBranch = ef.Branches.FirstOrDefault(dbBranch => dbBranch.branchName == newCar.CarBranch.BranchName); if (selectedBranch == null) { return(false); } CarType selectedCarType = ef.CarTypes.FirstOrDefault(dbCarType => dbCarType.model == newCar.CarType.Model); if (selectedCarType == null) { return(false); } Car newDbCar = new Car { currentKilometerage = newCar.CarCurrentKilometerage, image = newCar.CarImage, isFitForRental = newCar.CarIsFitForRental, carNumber = newCar.CarNumber, branchId = selectedBranch.BranchId, carTypeId = selectedCarType.carTypeId, }; ef.Cars.Add(newDbCar); ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// SelectAllAuthors reads all the Authors from the DB by the EF ref /// and maps the DAL objects to BOL objects /// </summary> static public CarTypeModel[] SelectAllCarTypes() { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { return(ef.CarTypes.Select(dbUser => new CarTypeModel { // CarTypeId = dbUser.carTypeId, Manufacturer = dbUser.manufacturer, Model = dbUser.model, DailyCost = dbUser.dailyCost, DayDelayCost = dbUser.dayDelayCost, ManufactureYear = dbUser.manufactureYear, Gear = dbUser.gear, }).ToArray()); } } catch (Exception) { return(null); } }
/// <summary> /// InsertBook inserts a new Book to the DB by the EF ref /// maps the `newBook` parameter (BOL object) to a `Book` (DAL object) /// and returns bool value - if the action was success /// </summary> static public bool InsertOrder(OrderModel newOrder) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { User selectedUser = ef.Users.FirstOrDefault(dbUser => dbUser.userName == newOrder.OrderUser.UserName); if (selectedUser == null) { return(false); } Car selectedCar = ef.Cars.FirstOrDefault(dbCar => dbCar.carNumber == newOrder.OrderCar.CarNumber); if (selectedCar == null) { return(false); } Order newDbOrder = new Order { startDate = newOrder.OrderStartDate, returnDate = newOrder.OrderReturnDate, actualReturnDate = newOrder.OrderActualReturnDate, carId = selectedCar.carId, userId = selectedUser.userId, }; ef.Orders.Add(newDbOrder); ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// SelectAllBooks reads all the Books from the DB by the EF ref /// and maps the DAL objects to BOL objects /// </summary> static public CarModel[] SelectAllCars() { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { return(ef.Cars.Select(dbCar => new CarModel { CarCurrentKilometerage = dbCar.currentKilometerage, CarImage = dbCar.image, CarIsFitForRental = dbCar.isFitForRental, CarNumber = dbCar.carNumber, CarBranch = new BranchModel { BranchAddress = dbCar.Branch.address, BranchLatitude = dbCar.Branch.latitude, BranchLongitude = dbCar.Branch.longitude, BranchName = dbCar.Branch.branchName, }, CarType = new CarTypeModel { // CarTypeId = dbCar.CarType.carTypeId, DailyCost = dbCar.CarType.dailyCost, DayDelayCost = dbCar.CarType.dayDelayCost, Gear = dbCar.CarType.gear, Manufacturer = dbCar.CarType.manufacturer, ManufactureYear = dbCar.CarType.manufactureYear, Model = dbCar.CarType.model, } }).ToArray()); } } catch (Exception) { return(null); } }
/// <summary> /// InsertAuthor inserts a new Author to the DB by the EF ref /// maps the `newAuthor` parameter (BOL object) to a `Author` (DAL object) /// and returns bool value - if the action was success /// </summary> static public bool InsertBranch(BranchModel newBranch) { try { using (CarsRentalEntities ef = new CarsRentalEntities()) { Branch newDbBranch = new Branch { address = newBranch.BranchAddress, latitude = newBranch.BranchLatitude, longitude = newBranch.BranchLongitude, branchName = newBranch.BranchName, }; ef.Branches.Add(newDbBranch); ef.SaveChanges(); return(true); } } catch (Exception) { return(false); } }