public static List <CarTypeModel> GetSpecificCarType(int crtyid) { try { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { return(db.CarTypes.Where(w => w.CarTypeID == crtyid && !w.IsDeleted).Select(ctid => new CarTypeModel { CarTypeID = ctid.CarTypeID, Manufacturer = ctid.Manufacturer, Model = ctid.Model, CarYear = ctid.CarYear, DailyRate = ctid.DailyRate, LateDailyRate = ctid.LateDailyRate, IsAutomatic = ctid.IsAutomatic, IsDeleted = ctid.IsDeleted }).ToList()); } } catch (Exception) { return(null); } }
/// getSpecificUser select a specific Car from the DB by the EF ref /// by the userID parameter. /// and maps the DAL objects to BOL objects public static List <UserModel> GetSpecificUser(int userID) { try { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { return(db.Users.Where(w => w.UserID == userID && !w.IsDeleted).Select(uid => new UserModel { UserID = uid.UserID, UserName = uid.UserName, FirstName = uid.FirstName, LastName = uid.LastName, ID = uid.ID, Birthdate = uid.Birthdate, Email = uid.Email, Password = uid.Password, UserPic = uid.UserPic, UserPermission = uid.UserPermission, }).ToList()); } } catch (Exception) { return(null); } }
//getuserlogin gets the user+pass and returns a user if found public static UserModel GetUserLogin(string name, string password) { try { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { User dbUser = db.Users.FirstOrDefault(u => u.UserName == name && u.Password == password); if (dbUser != null) { UserModel user = new UserModel { UserName = dbUser.UserName, UserPermission = dbUser.UserPermission, UserID = dbUser.UserID, FirstName = dbUser.FirstName, LastName = dbUser.LastName, ID = dbUser.ID, Birthdate = dbUser.Birthdate, Email = dbUser.Email, Password = dbUser.Password, UserPic = dbUser.UserPic, }; return(user); } } } catch (Exception) { } return(null); }
public static bool DeleteOrder(int orderID) { try { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { Order selectedOrder = null; if (orderID > 0) { selectedOrder = db.Orders.FirstOrDefault(x => x.OrderID == orderID); if (selectedOrder == null) { return(false); } } db.Orders.Remove(selectedOrder); db.SaveChanges(); return(true); } } catch (Exception ex) { return(false); } }
public static List <CarTypeModel> GetAllCarsTypes(string showDeleted = "") { List <CarTypeModel> ctm = null; using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { List <CarType> ct = null; if (showDeleted == "") { ct = db.CarTypes.Where(w => !w.IsDeleted).ToList(); } else { ct = db.CarTypes.Where(w => !w.IsDeleted && db.Cars.Count(c => c.CarTypeID == w.CarTypeID && !c.IsDeleted) > 0).ToList(); } ctm = ct.Select(x => new CarTypeModel() { CarTypeID = x.CarTypeID, Manufacturer = x.Manufacturer, Model = x.Model, CarYear = x.CarYear, DailyRate = x.DailyRate, LateDailyRate = x.LateDailyRate, IsAutomatic = x.IsAutomatic }).ToList(); } return(ctm); }
public static bool InsertUpdateDeleteUser(UserModel editUser) { try { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { User selectedUser = null; if (editUser.UserID > 0) { selectedUser = db.Users.FirstOrDefault(x => x.UserID == editUser.UserID && !x.IsDeleted); if (selectedUser == null) { return(false); } } else { selectedUser = new User(); } if (!editUser.IsDeleted) { selectedUser.UserName = editUser.UserName; selectedUser.FirstName = editUser.FirstName; selectedUser.LastName = editUser.LastName; selectedUser.ID = editUser.ID; selectedUser.Birthdate = editUser.Birthdate; selectedUser.Email = editUser.Email; selectedUser.Password = editUser.Password; selectedUser.UserPic = editUser.UserPic; selectedUser.UserPermission = editUser.UserPermission; } else { selectedUser.IsDeleted = true; } if (editUser.UserID == 0) { db.Users.Add(selectedUser); } db.SaveChanges(); return(true); } } catch (Exception ex) { return(false); } }
public static bool InsertUpdateDeleteCar(CarModel editCar) { try { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { Car selectedCar = null; if (editCar.CarID > 0) { selectedCar = db.Cars.FirstOrDefault(x => x.CarID == editCar.CarID && !x.IsDeleted); if (selectedCar == null) { return(false); } } else { selectedCar = new Car(); } if (!editCar.IsDeleted) { selectedCar.LicenseNumber = editCar.LicenseNumber; selectedCar.CurrentKilometers = editCar.CurrentKilometers; selectedCar.IsOperative = editCar.IsOperative; selectedCar.BranchLocation = editCar.BranchLocation.BranchID; selectedCar.CarTypeID = editCar.CarInfo.CarTypeID; selectedCar.CarPic = editCar.CarPic; } else { selectedCar.IsDeleted = true; } if (editCar.CarID == 0) { db.Cars.Add(selectedCar); } db.SaveChanges(); return(true); } } catch (Exception ex) { return(false); } }
public static bool InsertUpdateDeleteCarType(CarTypeModel editCarType) { try { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { CarType selectedCarType = null; if (editCarType.CarTypeID > 0) { selectedCarType = db.CarTypes.FirstOrDefault(x => x.CarTypeID == editCarType.CarTypeID && !x.IsDeleted); if (selectedCarType == null) { return(false); } } else { selectedCarType = new CarType(); } selectedCarType.Manufacturer = editCarType.Manufacturer; selectedCarType.Model = editCarType.Model; selectedCarType.CarYear = editCarType.CarYear; selectedCarType.DailyRate = editCarType.DailyRate; selectedCarType.LateDailyRate = editCarType.LateDailyRate; selectedCarType.IsAutomatic = editCarType.IsAutomatic; if (editCarType.IsDeleted) { selectedCarType.IsDeleted = true; } if (editCarType.CarTypeID == 0) { db.CarTypes.Add(selectedCarType); } db.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
public static bool InsertUpdateCloseOrder(OrderModel editOrder) { try { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { Order selectedOrder = null; if (editOrder.OrderID > 0) { selectedOrder = db.Orders.FirstOrDefault(x => x.OrderID == editOrder.OrderID /*&& !x.IsActiveOrder*/); if (selectedOrder == null) { return(false); } } else { selectedOrder = new Order(); } { selectedOrder.OrderDate = editOrder.OrderDate; selectedOrder.OrderStart = editOrder.OrderStart; selectedOrder.PlannedEnd = editOrder.PlannedEnd; selectedOrder.ActualEnd = editOrder.ActualEnd; selectedOrder.OrigianlCost = editOrder.OrigianlCost; selectedOrder.ActualCost = editOrder.ActualCost; selectedOrder.UserID = editOrder.UserID.UserID; selectedOrder.LicenseNumber = editOrder.Car.LicenseNumber; selectedOrder.IsActiveOrder = editOrder.IsActiveOrder; } if (editOrder.OrderID == 0) { db.Orders.Add(selectedOrder); } db.SaveChanges(); return(true); } } catch (Exception ex) { return(false); } }
public static List <BranchModel> GetAllBranches() { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { return(db.Branches.Where(w => !w.IsDeleted).Select(x => new BranchModel { BranchID = x.BranchID, BranchName = x.BranchName, BranchAddress = x.BranchAddress, BranchTel = x.BranchTel, BranchLatitude = x.BranchLatitude, BarnchLongitude = x.BarnchLongitude, }).ToList()); } }
public static bool InsertUpdateDeleteBranches(BranchModel editBranch) { try { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { Branch selecteBranch = null; if (editBranch.BranchID > 0) { selecteBranch = db.Branches.FirstOrDefault(x => x.BranchID == editBranch.BranchID && !x.IsDeleted); if (selecteBranch == null) { return(false); } } else { selecteBranch = new Branch(); } if (!editBranch.IsDeleted) { selecteBranch.BranchName = editBranch.BranchName; selecteBranch.BranchTel = editBranch.BranchTel; selecteBranch.BranchAddress = editBranch.BranchAddress; selecteBranch.BranchLatitude = editBranch.BranchLatitude; selecteBranch.BarnchLongitude = editBranch.BarnchLongitude; } else { selecteBranch.IsDeleted = true; } if (editBranch.BranchID == 0) { db.Branches.Add(selecteBranch); } db.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
/// getSpecificCar select a specific Car from the DB by the EF ref /// by the carID parameter. /// and maps the DAL objects to BOL objects public static List <CarModel> GetSpecificCar(int carID) { try { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { return(db.Cars.Where(w => w.CarID == carID && !w.IsDeleted).Select(x => new CarModel { CarID = x.CarID, LicenseNumber = x.LicenseNumber, CurrentKilometers = x.CurrentKilometers, IsOperative = x.IsOperative, CarPic = x.CarPic, IsDeleted = x.IsDeleted, CarInfo = new CarTypeModel() { CarTypeID = x.CarTypeID, Manufacturer = x.CarType.Manufacturer, Model = x.CarType.Model, IsAutomatic = x.CarType.IsAutomatic, CarYear = x.CarType.CarYear, DailyRate = x.CarType.DailyRate, LateDailyRate = x.CarType.LateDailyRate }, BranchLocation = new BranchModel() { BranchID = x.Branch.BranchID, BranchName = x.Branch.BranchName, BranchAddress = x.Branch.BranchAddress, BranchTel = x.Branch.BranchTel, BranchLatitude = x.Branch.BranchLatitude, BarnchLongitude = x.Branch.BarnchLongitude, } }).ToList()); } } catch (Exception) { return(null); } }
/// getAllCars reads all the Cars from the DB by the EF ref /// and maps the DAL objects to BOL objects public static List <CarModel> GetAllCars() { try { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { return(db.Cars.Where(w => !w.IsDeleted).Select(x => new CarModel { CarID = x.CarID, LicenseNumber = x.LicenseNumber, CurrentKilometers = x.CurrentKilometers, IsOperative = x.IsOperative, CarPic = x.CarPic, CarInfo = new CarTypeModel() { CarTypeID = x.CarTypeID, Manufacturer = x.CarType.Manufacturer, Model = x.CarType.Model, IsAutomatic = x.CarType.IsAutomatic, CarYear = x.CarType.CarYear, DailyRate = x.CarType.DailyRate, LateDailyRate = x.CarType.LateDailyRate }, BranchLocation = new BranchModel() { BranchID = x.Branch.BranchID, BranchName = x.Branch.BranchName, BranchAddress = x.Branch.BranchAddress, BranchTel = x.Branch.BranchTel, BranchLatitude = x.Branch.BranchLatitude, BarnchLongitude = x.Branch.BarnchLongitude, } }).OrderByDescending(o => o.CarInfo.CarTypeID).ToList()); //send all cars sorted by the cartype } } catch (Exception) { return(null); } }
/// getAlUsers reads all the Cars from the DB by the EF ref /// and maps the DAL objects to BOL objects public static List <UserModel> GetAllUsers() { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { return(db.Users.Where(w => !w.IsDeleted).Select(x => new UserModel() { UserID = x.UserID, UserName = x.UserName, FirstName = x.FirstName, LastName = x.LastName, ID = x.ID, Birthdate = x.Birthdate, Email = x.Email, Password = x.Password, UserPic = x.UserPic, UserPermission = x.UserPermission, }).OrderBy(o => o.UserName).ToList()); } }
public static bool CheckIfUnavaliabe(DateTime start, DateTime end, string licenseNumber) //will return true if car is unavaliable on selected times. { try { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { return (db.Orders.Where(w => w.IsActiveOrder).Where(w => w.LicenseNumber == licenseNumber && ( (w.PlannedEnd <= end && w.PlannedEnd >= start) || (w.OrderStart <= end && w.OrderStart >= start) || (w.PlannedEnd >= end && w.OrderStart <= start))).ToList().Count() > 0); } } catch (Exception ex) { return(false); } //if (thisCarOrdersList.Count() > 0) res = true; //return res; }
public static List <BranchModel> GetSpecificBranch(int sbid) { try { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { return(db.Branches.Where(w => w.BranchID == sbid && !w.IsDeleted).Select(bid => new BranchModel { BranchID = bid.BranchID, BranchName = bid.BranchName, BranchTel = bid.BranchTel, BranchAddress = bid.BranchAddress, BranchLatitude = bid.BranchLatitude, BarnchLongitude = bid.BarnchLongitude, IsDeleted = bid.IsDeleted, }).ToList()); } } catch (Exception) { return(null); } }
/// GetSpecificOrder select a specific Order from the DB by the EF ref /// by the orderID parameter. /// and maps the DAL objects to BOL objects public static List <OrderModel> GetSpecificOrder(int orderID) { List <OrderModel> specificOrders = null; try { using (CarRentEntitiesModel db = new CarRentEntitiesModel()) { specificOrders = db.Orders.Where(w => w.OrderID == orderID).Select(x => new OrderModel { OrderID = x.OrderID, OrderDate = x.OrderDate, OrderStart = x.OrderStart, PlannedEnd = x.PlannedEnd, ActualEnd = x.ActualEnd, OrigianlCost = x.OrigianlCost, ActualCost = x.ActualCost, IsActiveOrder = x.IsActiveOrder, Car = new CarModel() { LicenseNumber = x.Car.LicenseNumber, CurrentKilometers = x.Car.CurrentKilometers, IsOperative = x.Car.IsOperative, CarPic = x.Car.CarPic, CarID = x.Car.CarID, CarInfo = new CarTypeModel() { CarTypeID = x.Car.CarTypeID, Manufacturer = x.Car.CarType.Manufacturer, Model = x.Car.CarType.Model, IsAutomatic = x.Car.CarType.IsAutomatic, CarYear = x.Car.CarType.CarYear, DailyRate = x.Car.CarType.DailyRate, LateDailyRate = x.Car.CarType.LateDailyRate }, BranchLocation = new BranchModel() { BranchName = x.Car.Branch.BranchName, BranchAddress = x.Car.Branch.BranchAddress, BranchTel = x.Car.Branch.BranchTel, BranchLatitude = x.Car.Branch.BranchLatitude, BarnchLongitude = x.Car.Branch.BarnchLongitude, BranchID = x.Car.Branch.BranchID } }, UserID = new UserModel() { UserID = x.User.UserID, FirstName = x.User.FirstName, LastName = x.User.LastName, ID = x.User.ID, UserName = x.User.UserName, Birthdate = x.User.Birthdate, isMale = x.User.isMale, Email = x.User.Email, Password = x.User.Password, UserPic = x.User.UserPic, UserPermission = x.User.UserPermission } }).ToList(); } } catch { } return(specificOrders); }