Exemplo n.º 1
0
        private void lbNotesList_SelectedIndexChanged(object sender, EventArgs e)
        {
            selectedNote = lbNotesList.SelectedIndex;

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

            var notes   = (Notes)lbNotesList.Items[selectedNote];
            var context = new NotesEntities();

            rtbNoteContent.Text = context.Notes.First(n => n.id == notes.id).text;
        }
Exemplo n.º 2
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.º 3
0
        private void RefreshNotesList()
        {
            lbNotesList.Items.Clear();

            /*var notes = NotesModel.GetNotes();
             * foreach(var note in notes) {
             *  lbNotesList.Items.Add(note);
             * }*/

            using (var context = new NotesEntities()) {
                foreach (Notes note in context.Notes)
                {
                    lbNotesList.Items.Add(note);
                }
            }
        }
Exemplo n.º 4
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.º 5
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();
                }
            }
        }