示例#1
0
文件: MainVM.cs 项目: Gramli/Noter
 /// <summary>
 /// Remove note
 /// </summary>
 /// <param name="note"></param>
 public void RemoveNote(Note note)
 {
     using (NoterDbContext ctx = this.dbConnector.GetContext())
     {
         ctx.Entry(note).State = System.Data.Entity.EntityState.Deleted;
         ctx.SaveChanges();
     }
 }
示例#2
0
文件: MainVM.cs 项目: Gramli/Noter
        /// <summary>
        /// Set note by ArchivedEnum
        /// </summary>
        /// <param name="note"></param>
        /// <param name="type"></param>
        public void SetArchived(Note note, ArchivedEnum type)
        {
            using (NoterDbContext db = this.dbConnector.GetContext())
            {
                note.Archived        = type;
                db.Entry(note).State = System.Data.Entity.EntityState.Modified;

                db.SaveChanges();
            }
        }
示例#3
0
文件: AddNoteVM.cs 项目: Gramli/Noter
        /// <summary>
        /// Save or Edit note and save changes to database
        /// </summary>
        public void SaveChanges()
        {
            using (NoterDbContext db = this.connector.GetContext())
            {
                if (this.note != null)
                {
                    this.note.Name            = this.Name;
                    this.note.Text            = this.Text;
                    this.note.Priority        = this.Priority;
                    this.note.Edited          = DateTime.Now.ToString(Note.DateTimeFormat);
                    db.Entry(this.note).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    Note newNote = new Note(this.Name, this.Text, this.Priority);
                    db.Notes.Add(newNote);
                }

                db.SaveChanges();
            }
        }