private void RentCar_Click(object sender, System.Windows.RoutedEventArgs e) { Vehicle selectedVehicle = VehicleTable.SelectedItem != null ? VehicleTable.SelectedItem as Vehicle : null; if (selectedVehicle != null) { //todo implement pay logic try { List <BlackList> blackLists = new BlackListDAO().GetBlackLists(userId: UserManager.CurrentUser.Id); if (blackLists.Count != 0) { if (blackLists.First().Banned) { NotificationLabel.ShowError("You are banned! You cannot make a rental!"); } } List <BankAccount> list = new BankAccountDAO().GetBankAccounts(userId: UserManager.CurrentUser.Id); if (list.Count == 0) { NotificationLabel.ShowError("Please go to settings and add your bank account info"); return; } new RentDAO().Insert(new Rent() { BeginTime = DateTime.Now, Returned = false, Paid = false, VehicleId = selectedVehicle.Id, VehicleName = selectedVehicle.Name, UserId = UserManager.CurrentUser.Id }); selectedVehicle.UserId = UserManager.CurrentUser.Id; new VehicleDAO().Update(selectedVehicle); ((List <Vehicle>)VehicleTable.ItemsSource).Remove((Vehicle)VehicleTable.SelectedItem); MyFinesTable.Items.Refresh(); NotificationLabel.ShowSuccess("Rental successful !"); } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Could not process rental"); selectedVehicle.UserId = null; } } else { NotificationLabel.ShowError("Nothing selected"); } }
private void AddToBlackList_Click(object sender, System.Windows.RoutedEventArgs e) { if (AllUsersTable.SelectedItem == null) { NotificationLabel.ShowError("Please select a User first"); return; } User selectedUser = (User)AllUsersTable.SelectedItem; try { List <BlackList> blackLists = new BlackListDAO().GetBlackLists(userId: selectedUser.Id); if (blackLists.Count == 0) { new BlackListDAO().Insert(new BlackList() { UserId = selectedUser.Id, Warnings = 1 }); NotificationLabel.ShowSuccess("User added to blacklist!"); } else { string additionalMessage = ""; BlackList blackList = blackLists[0]; blackList.Warnings++; new BlackListDAO().Update(blackList); if (blackList.Banned) { additionalMessage = " He is now banned"; } NotificationLabel.ShowSuccess("User warnings increased to " + blackList.Warnings + " !" + additionalMessage); } } catch (Exception ex) { DebugLog.WriteLine(ex); NotificationLabel.ShowError("Could not add User to Blacklist"); } }