public List <Tuple <DateTime, DateTime> > getCarUnavailableDates(string licensePlate, DateTime fromDate) { List <Tuple <DateTime, DateTime> > reservationDateRanges = new List <Tuple <DateTime, DateTime> >(); using (CarRentalEntities carEntities = new CarRentalEntities()) { var car = carEntities.Cars.Where(c => c.LicensePlate == licensePlate).FirstOrDefault(); if (car != null) { foreach (var order in carEntities.RentalOrders) { if (order.CarId != car.CarId || order.ActualRentEndDate != null || order.RentEndDate.Date <= fromDate.Date) { continue; } reservationDateRanges.Add(new Tuple <DateTime, DateTime>(order.RentStartDate, order.RentEndDate)); } } } return(reservationDateRanges); }
public bool DeleteOrder(int ordid) { try { using (CarRentalEntities db = new CarRentalEntities()) { Order b = db.Orders.FirstOrDefault(bk => bk.OrderID == ordid); if (b != null) { db.Orders.Remove(b); db.SaveChanges(); return(true); } } return(false); } catch (Exception) { return(false); } }
public List <CarModel> getAllCars(bool includeNonFunctional = false)//workers and manager can view non-functional cars { List <CarModel> cars = new List <CarModel>(); using (CarRentalEntities carEntities = new CarRentalEntities()) { foreach (Car car in carEntities.Cars.Where(c => includeNonFunctional || c.IsConditionOK)) { cars.Add(new CarModel() { CarType = CarTypesManager.getCarTypeById(car.CarTypeId), CurrentKM = car.Kilometers, CarPhoto = car.Photo, IsFunctional = car.IsConditionOK, LicensePlate = car.LicensePlate, Branch = BranchesManager.getBranchById(car.BranchId) }); } } return(cars); }
public bool DeleteUser(int id) { try { using (CarRentalEntities db = new CarRentalEntities()) { User b = db.Users.Where(d => d.UserID == id).FirstOrDefault(); if (b != null) { db.Users.Remove(b); db.SaveChanges(); return(true); } } return(false); } catch (Exception) { return(false); } }
public bool DeleteOrder(RentalOrderModel updatedOrder) { try { using (CarRentalEntities carEntities = new CarRentalEntities()) { RentalOrder order = carEntities.RentalOrders.Where(o => o.RentalOrderId == updatedOrder.OrderId).FirstOrDefault(); if (order == null) { throw new ArgumentException($"Order number {updatedOrder.OrderId} was not found"); } carEntities.RentalOrders.Remove(order); carEntities.SaveChanges(); } return(true); } catch { return(false); } }
internal static CarTypeModel getCarTypeById(int carTypeId) { CarType carType; using (CarRentalEntities carEntities = new CarRentalEntities()) { carType = carEntities.CarTypes.Where(t => t.CarTypeId == carTypeId).FirstOrDefault(); } if (carType == null) { return(null); } return(new CarTypeModel { Producer = carType.Manufacturer, Model = carType.Model, ManufacturingYear = carType.ProductionYear, Gear = carType.AutomaticGear ? CarTypeModel.AUTOMATIC : CarTypeModel.MANUAL, DailyCost = carType.DailyCost, DailyPenaltyFee = carType.DailyPenaltyFee }); }
public bool UpdateCarType(CarTypeModel updatedCarType) { try { using (CarRentalEntities carEntities = new CarRentalEntities()) { CarType carType = carEntities.CarTypes.Where(t => t.Manufacturer == updatedCarType.Producer && t.Model == updatedCarType.Model && t.ProductionYear == updatedCarType.ManufacturingYear && (t.AutomaticGear && updatedCarType.Gear == CarTypeModel.AUTOMATIC || !t.AutomaticGear && updatedCarType.Gear == CarTypeModel.MANUAL)).FirstOrDefault(); if (carType == null) { throw new ArgumentException($"Car type with the required specifications was not found"); //todo: write the specifications } carType.DailyCost = updatedCarType.DailyCost; carType.DailyPenaltyFee = updatedCarType.DailyPenaltyFee; carEntities.SaveChanges(); } return(true); } catch { return(false); } }
public CarModel getCarByLicensePlate(string licensePlate) { Car car; using (CarRentalEntities carEntities = new CarRentalEntities()) { car = carEntities.Cars.Where(c => c.LicensePlate == licensePlate).FirstOrDefault(); } if (car == null) { return(null); } return(new CarModel() { CarType = CarTypesManager.getCarTypeById(car.CarTypeId), CurrentKM = car.Kilometers, CarPhoto = car.Photo, IsFunctional = car.IsConditionOK, LicensePlate = car.LicensePlate, Branch = BranchesManager.getBranchById(car.BranchId) }); }
/// <summary> /// Vérifie qu'un utilisateur possède bien un role selon le nom du rôle. /// </summary> /// <param name="mail"></param> /// <param name="roleName"></param> /// <returns></returns> bool IRoleEngine.Is_User_In_Role(string mail, string roleName) { using (CarRentalEntities context = new CarRentalEntities()) { try { User user = context.usp_UserRole_GET_USER_IN_ROLE(mail, roleName).FirstOrDefault(); if (user != null) { return(true); } else { return(false); } } catch (Exception) { throw; } } }
public static string loginUser(string userName, string userPassword) //returns response that includes the token and user model info in a json string { User user; UserRole role = null; using (CarRentalEntities carEntities = new CarRentalEntities()) { user = carEntities.Users.Where(c => c.UserName == userName && c.Password == userPassword).FirstOrDefault(); if (user != null) { role = carEntities.UserRoles.Where(r => r.UserRoleId == user.UserRoleId).FirstOrDefault(); } } if (user == null) { return(string.Empty); } UserModel userModel = toUserModel(user, role); var token = createToken(userName, userPassword); var jsonString = token; return(jsonString); }
public CarModel AddCar(CarModel addCar) { try { using (CarRentalEntities carEntities = new CarRentalEntities()) { Car car = new Car(); car.CarTypeId = CarTypesManager.getCarTypeId(addCar.CarType.Producer, addCar.CarType.Model, addCar.CarType.ManufacturingYear, addCar.CarType.Gear); car.Kilometers = addCar.CurrentKM; car.Photo = addCar.CarPhoto; car.IsConditionOK = addCar.IsFunctional; car.BranchId = addCar.Branch.BranchId; car.LicensePlate = addCar.LicensePlate; carEntities.Cars.Add(car); carEntities.SaveChanges(); } return(addCar); } catch (Exception e) { return(null); } }
public UserModel AddUser(UserModel addUser) { try { using (CarRentalEntities carEntities = new CarRentalEntities()) { UserRole userRole = carEntities.UserRoles.Where(r => r.UserRoleName == addUser.Role).FirstOrDefault(); if (userRole == null) { throw new Exception("No valid user role"); } User user = toDALUser(addUser, userRole.UserRoleId); carEntities.Users.Add(user); carEntities.SaveChanges(); } return(addUser); } catch (Exception e) { throw; } }
public CarTypeModel AddCarType(CarTypeModel addCarType) { try { using (CarRentalEntities carEntities = new CarRentalEntities()) { CarType carType = new CarType(); carType.Manufacturer = addCarType.Producer; carType.Model = addCarType.Model; carType.ProductionYear = addCarType.ManufacturingYear; carType.AutomaticGear = addCarType.Gear == CarTypeModel.AUTOMATIC; carType.DailyCost = addCarType.DailyCost; carType.DailyPenaltyFee = addCarType.DailyPenaltyFee; carEntities.CarTypes.Add(carType); carEntities.SaveChanges(); } return(addCarType); } catch { return(null); } }
public bool UpdateUser(UserModel updatedUser) { try { using (CarRentalEntities carEntities = new CarRentalEntities()) { User user = carEntities.Users.Where(u => u.UserName == updatedUser.UserName).FirstOrDefault(); if (user == null) { throw new ArgumentException($"User name {updatedUser.UserName} was not found"); } UserRole role = carEntities.UserRoles.Where(r => r.UserRoleName == updatedUser.Role).FirstOrDefault(); if (role == null) { throw new ArgumentException($"User role {updatedUser.Role} was not found"); } user.FullName = updatedUser.FullName; user.IdentificationNumber = updatedUser.IdentificationNumber; user.UserName = updatedUser.UserName; user.BirthDate = updatedUser.BirthDate; user.IsFemale = updatedUser.IsFemale; user.Email = updatedUser.Email; user.Password = updatedUser.Password; user.Photo = updatedUser.UserPhoto; user.UserRoleId = role.UserRoleId; carEntities.SaveChanges(); } return(true); } catch (Exception e) { return(false); } }
public ManageVehicleListing() { InitializeComponent(); _db = new CarRentalEntities(); }
public bool AddUser(UserModel useradd) { using (CarRentalEntities db = new CarRentalEntities()) { User newuser = db.Users.Where(a => a.UserID == useradd.UserID).FirstOrDefault(); if (newuser != null) { return(false); } }; User u = new User { //UserID = useradd.UserID, FullName = useradd.FullName, TeudatZeut = useradd.TeudatZeut, UserName = useradd.UserName, Email = useradd.Email, Gender = useradd.Gender, Password = useradd.Password, IsValidUSer = useradd.IsValidUSer, //PicPath = useradd.PicPath, Birthday = useradd.Birthday, //UserTypeID = useradd.UserTypeID }; try { db.Users.Add(u); db.SaveChanges(); var typeofuser = db.Users.Where(x => x.UserTypeID == u.UserTypeID).FirstOrDefault(); var userStore = new UserStore <ApplicationUser>(new ApplicationDbContext()); var userManager = new UserManager <ApplicationUser>(userStore); ApplicationUser uIdentity = new ApplicationUser { UserID = useradd.UserID, BirthDate = useradd.Birthday, UserTypeID = useradd.UserTypeID, FullName = useradd.FullName, TeudatZeut = useradd.TeudatZeut, UserName = useradd.UserName, Email = useradd.Email, Gender = useradd.Gender, Password = useradd.Password, IsValidUSer = useradd.IsValidUSer, PicPath = useradd.PicPath, Phone = useradd.Phone // TypeOfUser = typeofuser.UserType.TypeOfUser }; //IdentityResult identified = userManager.Create(uIdentity, useradd.Password); return(true); } catch (System.Data.Entity.Core.UpdateException) { return(false); } catch (System.Data.Entity.Infrastructure.DbUpdateException) //DbContext { return(false); } }
public LoginForm() { InitializeComponent(); _db = new CarRentalEntities(); }