private void ShowAddServiceDialog() { using (var d = new AddServiceDialog(_environment)) { d.Run(ListBox); } }
private async void AddServiceButton_Click(object sender, RoutedEventArgs e) { var dialog = new AddServiceDialog(Notifier); var result = await DialogHost.Show(dialog, "root"); if (result == null) { return; } try { if ((bool)result) { var eccService = new EccKeyServiceProvider(); var serviceKeyPair = eccService.CreateNew_secp256r1_ECKeyPair(); var userKeyPair = UserData.eccKeyPairs[0]; var masterKeyService = new KeyDerivationServiceProvider(); var crypto = new SymmetricCryptographyServiceProvider(); var derivedKey = eccService.EcdhDervieKey( new EccKeyPairBlob(userKeyPair.PublicKey.Curve, userKeyPair.PublicKey.PublicKey, null), serviceKeyPair, HashAlgorithmName.SHA256); var masterKey = masterKeyService.Pbkdf2Sha256DeriveKeyFromPassword(derivedKey, 16, 16); var encrypted = crypto.Aes128GcmEncrypt(masterKey.MasterKey, Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(dialog.Service))); var postModel = new EccCredentialPostModel() { EccDerivationBlob = new EccDerivationBlobModel() { Curve = serviceKeyPair.Curve, PublicKey = serviceKeyPair.PublicKey }, EccKeyPairId = userKeyPair.Id, SymmetricCiphertextBlob = new SymmetricCiphertextBlobModel() { AuthenticationTag = encrypted.AuthenticationTag, CipherDescription = encrypted.CipherDescription, Ciphertext = encrypted.Cipthertext, InitializationVector = encrypted.InitializationVector, DerivationDescription = masterKey.DerivationDescription, DerivationSalt = masterKey.DerivationSalt }, }; var PostResult = await UserData.ApiClient.ApiEcccredentialsPostAsync(postModel); Services.Add(dialog.Service); } } catch (ApiException <ProblemDetails> exc) { foreach (var error in ApiErrorsBuilder.GetErrorList(exc.Result.Errors)) { Notifier.ShowError(error); } } catch (Exception) { Notifier.ShowError("Unknown error"); } }
private void VehicleGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { registrationNo = VehicleGridView.Rows[e.RowIndex].Cells[1].Value.ToString(); if (VehicleGridView.Columns[e.ColumnIndex].Name == "AddJourney") { Vehicle vehicle = GetVehicleForRegNumber(registrationNo); if (vehicle != null) { AddJourneyDialog jDialog = new AddJourneyDialog(); bool requiresService = vehicle.RequiresService(); if (requiresService == false) { jDialog.StartPosition = FormStartPosition.CenterParent; jDialog.ControlBox = false; jDialog.Text = String.Empty; jDialog.RegistrationNumber = registrationNo; DialogResult result = jDialog.ShowDialog(); if (result == DialogResult.OK) { Journey newJourney = new Journey(jDialog.RentalType, jDialog.NumberDays, jDialog.KmsTravelled); { vehicle.AddJourney(newJourney); populateOutputs(); } } } else { MessageBox.Show("Sorry. This vehicle requires a service and cannot be rented", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else if (VehicleGridView.Columns[e.ColumnIndex].Name == "AddFuel") { AddFuelDialog fDialog = new Dialogs.AddFuelDialog(); fDialog.StartPosition = FormStartPosition.CenterParent; fDialog.ControlBox = false; fDialog.Text = String.Empty; fDialog.RegistrationNumber = registrationNo; DialogResult result = fDialog.ShowDialog(); if (result == DialogResult.OK) { FuelPurchase fuelPurchase = new FuelPurchase(fDialog.FuelQuantity); Vehicle vehicle = GetVehicleForRegNumber(registrationNo); if (vehicle != null) { vehicle.AddFuelPurchase(fuelPurchase); populateOutputs(); } } } else if (VehicleGridView.Columns[e.ColumnIndex].Name == "AddService") { Vehicle vehicle = GetVehicleForRegNumber(registrationNo); if (vehicle != null) { int TotalKmsTravelled = vehicle.GetTotalKms(); AddServiceDialog sDialog = new AddServiceDialog(); sDialog.TotalKmsTravelled = TotalKmsTravelled; sDialog.StartPosition = FormStartPosition.CenterParent; sDialog.ControlBox = false; sDialog.Text = String.Empty; sDialog.RegistrationNumber = registrationNo; DialogResult result = sDialog.ShowDialog(); if (result == DialogResult.OK) { Service service = new Service(TotalKmsTravelled); vehicle.AddService(service); populateOutputs(); } } } }
private void ShowAddServiceDialog() { using(var d = new AddServiceDialog(_environment)) { d.Run(ListBox); } }