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 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 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); } }