private void StickyNoteListBox_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { StickyNote Note = StickyNoteListBox.SelectedItem as StickyNote; StickyNoteForm stickyForm = new StickyNoteForm(); stickyForm.NewStickyNote = Note; if ((bool)stickyForm.ShowDialog()) { if (!Note.Same(stickyForm.NewStickyNote)) { StickyNoteListBox.Items.Remove(Note); using (var Ctx = new Context()) { Note.Update(stickyForm.NewStickyNote); Ctx.Entry(Note).State = System.Data.Entity.EntityState.Modified; Ctx.SaveChanges(); } StickyNoteListBox.Items.Add(Note); } } else { StickyNoteListBox.Items.Remove(Note); //delete data data base using (var Ctx = new Context()) { Ctx.Entry(Note).State = System.Data.Entity.EntityState.Deleted; Ctx.SaveChanges(); } } }
private void AddBtn_Click(object sender, RoutedEventArgs e) { StickyNoteForm StickyNote = new StickyNoteForm(); if ((bool)StickyNote.ShowDialog()) { StickyNoteListBox.Items.Add(StickyNote.NewStickyNote); //add to data base using (var Ctx = new Context()) { Ctx.StickyNotes.Add(StickyNote.NewStickyNote); Ctx.SaveChanges(); } } }
private void StickyNoteListBox_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (this.StickyNoteListBox.SelectedItems != null) { var ctx = new Context(); StickyNote Note = StickyNoteListBox.SelectedItem as StickyNote; //اینجا وقتی نوت را می سازم همیشه //ID = 0 //و به همین دلیل عه که موقع پاک کردن یا اپدیت اکسپشن به وجود میاد //؟؟؟؟ StickyNoteForm recipeForm = new StickyNoteForm(); var note = ctx.StickyNotes.Where(x => (x.Title == Note.Title && x.Content == Note.Content)).SingleOrDefault(); recipeForm.NewStickyNote = Note; if ((bool)recipeForm.ShowDialog()) { StickyNoteListBox.Items.Remove(Note); using (var Ctx = new Context()) { Ctx.Entry(note).State = System.Data.Entity.EntityState.Modified; Ctx.SaveChanges(); } StickyNoteListBox.Items.Add(recipeForm.NewStickyNote); } else { this.StickyNoteListBox.Items.Remove(Note); //update data base using (var Ctx = new Context()) { Ctx.Entry(note).State = System.Data.Entity.EntityState.Deleted; Ctx.SaveChanges(); } } } }