private async void btnSave_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(txtNoteCaption.Text) || string.IsNullOrWhiteSpace(txtNoteCaption.Text)) { await (new MessageDialog(AppConstants.AppMessages[AppConstants.UsedLanguage]["np_verifyNoteCaption"]).ShowAsync()); return; } SimpleNotesModel model = new SimpleNotesModel(); SNItem item = new SNItem(); if (_noteItem == null) { item.N_caption = txtNoteCaption.Text; item.N_cid = (cboNoteCategory.SelectedItem as Category).c_id; item.N_text = txtNoteText.Text; item.N_timestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; if (TmpShedule.IsChanged) { item.N_timer_timestamp = TmpShedule.Schedule; TmpShedule.Clear(); ScheduledToast.CreateScheduledToast(item.N_timer_timestamp, model.GetLastId(), item.N_caption); } if (TmpPassword.IsChanged) { string hash = Hash.ComputeHash(TmpPassword.NewPassword); string encryptedNoteText = Cipher.Encrypt(txtNoteText.Text, TmpPassword.NewPassword, hash); TmpPassword.Clear(); item.N_text = encryptedNoteText; item.N_crypted = 1; item.N_shadow = hash; } model.AddNote(item); } else { item.N_id = _noteItem.N_id; item.N_caption = txtNoteCaption.Text; item.N_cid = (cboNoteCategory.SelectedItem as Category).c_id; item.N_text = txtNoteText.Text; if (TmpShedule.IsChanged) { item.N_timer_timestamp = TmpShedule.Schedule; TmpShedule.Clear(); ScheduledToast.DeleteScheduledToast(item.N_id); ScheduledToast.CreateScheduledToast(item.N_timer_timestamp, item.N_id, item.N_caption); } else { item.N_timer_timestamp = _noteItem.N_timer_timestamp; } if (TmpPassword.IsChanged) { string hash = Hash.ComputeHash(TmpPassword.NewPassword); string encryptedNoteText = Cipher.Encrypt(item.N_text, TmpPassword.NewPassword, hash); TmpPassword.Clear(); item.N_text = encryptedNoteText; item.N_crypted = 1; item.N_shadow = hash; } else { if (_noteItem.N_crypted == 1) { item.N_text = Cipher.Encrypt(item.N_text, TmpPassword.NewPassword, _noteItem.N_shadow); TmpPassword.Clear(); item.N_crypted = 1; item.N_shadow = _noteItem.N_shadow; } } model.EditNote(item); } Frame.GoBack(); }
private async void ShowNote(SNItem noteItem) { if (noteItem.N_crypted == 1) { PasswordRequestContentDialog dialog = new PasswordRequestContentDialog(noteItem); await dialog.ShowAsync(); if (dialog.Return == PasswordRequestContentDialogReturn.BtnOk) { AddEditeNotePageDataHelper.Clear(); AddEditeNotePageDataHelper.NoteText = Cipher.Decrypt(noteItem.N_text, TmpPassword.NewPassword, noteItem.N_shadow); } else { return; } } Frame.Navigate(typeof(AddEditNotePage), noteItem); }
public PasswordRequestContentDialog(SNItem noteItem) { this.InitializeComponent(); _noteItem = noteItem; }