public void SaveNote(Note note) { if (note.NoteId == 0) { context.Notes.Add(note); } else { Note dbEntry = context.Notes.Find(note.NoteId); if (dbEntry != null) { dbEntry.Date = note.Date; dbEntry.NoteStart = note.NoteStart; dbEntry.NoteFinish = note.NoteFinish; dbEntry.NoteText = note.NoteText; } } context.SaveChanges(); }
private void Add_Event_Execute(object sender, ExecutedRoutedEventArgs e) { Note eventNote = new Note(); if (dtpDate.SelectedDate == null) { dtpDate.SelectedDate = DateTime.Today; } eventNote.Date = (DateTime)dtpDate.SelectedDate; eventNote.NoteStart = cboHoursEventStart.Text + ":" + cboMinutesEventStart.Text; eventNote.NoteFinish = cboHoursEventFinish.Text + ":" + cboMinutesEventFinish.Text; eventNote.NoteText = myNote.Note.Trim(); _repository.SaveNote(eventNote); tbxNote.Text = ""; dataGrid_load(dataGrid1, (DateTime)dtpDate.SelectedDate); popupAddEvent.IsOpen = false; }
private void selection_note(object sender, SelectionChangedEventArgs e) { Note editNote = dataGrid1.SelectedItem as Note; if (editNote != null) { var editId = editNote.NoteId; responseOfDB = _repository.Get(editId); tbxNoteEdit.Text = responseOfDB.NoteText; dtpDate.DisplayDate = responseOfDB.Date; cboHoursEditStart.Text = responseOfDB.NoteStart.Substring(0, 2); cboMinutesEditStart.Text = responseOfDB.NoteStart.Substring(3); cboHoursEditFinish.Text = responseOfDB.NoteFinish.Substring(0, 2); cboMinutesEditFinish.Text = responseOfDB.NoteFinish.Substring(3); } }
private void Edit_Event_Execute(object sender, ExecutedRoutedEventArgs e) { Note edit = new Note(); if (dtpDate.SelectedDate == null) { dtpDate.SelectedDate = DateTime.Today; } edit.Date = dtpDate.DisplayDate; edit.NoteId = responseOfDB.NoteId; edit.NoteStart = cboHoursEditStart.Text + ":" + cboMinutesEditStart.Text; edit.NoteFinish = cboHoursEditFinish.Text + ":" + cboMinutesEditFinish.Text; edit.NoteText = myNote.Note; _repository.SaveNote(edit); tbxNoteEdit.Text = ""; dataGrid_load(dataGrid1, (DateTime)dtpDate.DisplayDate); popupEdit.IsOpen = false; }