예제 #1
0
        /*
         * btnSubmitSaveNote_Click event
         *
         * Save new note to database
         */
        private void btnSubmitSaveNote_Click(object sender, RoutedEventArgs e)
        {
            if (txtNewNote.Text.Trim().Length == 0 || txtNewNote.Text == "")
            {
                MessageBox.Show("Please enter note before saving !");
            }
            else
            {
                tblNote newNote = new tblNote()
                {
                    user_id    = int.Parse(txtUserId.Text),
                    note       = txtNewNote.Text,
                    created_at = DateTime.Now
                };

                _db.tblNotes.Add(newNote);
                _db.SaveChanges();

                int id = int.Parse(txtUserId.Text);
                gridUserNotes.ItemsSource     = _db.tblNotes.Where(n => n.user_id == id).ToList();
                btnSubmitUpdateNote.IsEnabled = false;
                btnSubmitSaveNote.IsEnabled   = true;
                txtNewNote.Text = "";
            }
        }
예제 #2
0
        /*
         * btnSubmitUpdateNote_Click event
         *
         * Update the note and save it to DataBase
         */
        private void btnSubmitUpdateNote_Click(object sender, RoutedEventArgs e)
        {
            if (txtNewNote.Text.Trim().Length == 0 || txtNewNote.Text == "")
            {
                MessageBox.Show("Please enter note before updating !");
            }
            else
            {
                int userId = int.Parse(txtUserId.Text);
                int id     = (gridUserNotes.SelectedItem as tblNote).id;

                tblNote updateNote = (from n in _db.tblNotes where n.id == id select n).Single();
                updateNote.user_id = userId;
                updateNote.note    = txtNewNote.Text;

                _db.SaveChanges();

                gridUserNotes.ItemsSource     = _db.tblNotes.Where(n => n.user_id == userId).ToList();
                btnSubmitUpdateNote.IsEnabled = false;
                btnSubmitSaveNote.IsEnabled   = true;
                txtNewNote.Text = "";
            }
        }