Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            /*var note = (Note)lbNotesList.Items[selectedNote];
             * note.Text = rtbNoteContent.Text;
             * NotesModel.UpdateNote(note);*/

            var notes      = (Notes)lbNotesList.Items[selectedNote];
            var context    = new NotesEntities();
            var resultNote = context.Notes.First(n => n.id == notes.id);

            if (resultNote != null)
            {
                resultNote.text = rtbNoteContent.Text;
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        private void btnNewNote_Click(object sender, EventArgs e)
        {
            string input = Interaction.InputBox("Unesite note", "Notes");

            /*var note = new Note(input, "");
             * if(!NotesModel.AddNote(note)) {
             *  MessageBox.Show("Doslo je do greške prilikom unosa Nota!",
             *      "Greška", MessageBoxButtons.OK, MessageBoxIcon.Error);
             * }*/

            var context = new NotesEntities();
            var newNote = new Notes()
            {
                name = input, text = ""
            };

            context.Notes.Add(newNote);
            context.SaveChanges();
            RefreshNotesList();
        }
Exemplo n.º 3
0
        private void lbNotesList_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                if (selectedNote != -1)
                {
                    rtbNoteContent.Text = "";

                    /*var note = (Note)lbNotesList.Items[selectedNote];
                     * NotesModel.DeleteNote(note);*/

                    var   notes = (Notes)lbNotesList.Items[selectedNote];
                    Notes selectedNoteEntity = new Notes()
                    {
                        id = notes.id
                    };
                    var context = new NotesEntities();
                    context.Notes.Attach(selectedNoteEntity);
                    context.Notes.Remove(selectedNoteEntity);
                    context.SaveChanges();
                    RefreshNotesList();
                }
            }
        }