Exemplo n.º 1
0
        public static bool RefreshTrash()
        {
            using (var _context = new DBSimpleNoteEntities())
            {
                var ID = 0;

                var trashList = (from t in _context.Trashes.AsEnumerable()
                                 select t)
                                .Select(x => new Trash
                {
                    ID          = x.ID,
                    description = x.description,
                    dateCreated = x.dateCreated,
                    tags        = x.tags,
                    isPinned    = x.isPinned
                }).ToList();



                foreach (Trash trash in trashList)
                {
                    var removeTrash = (from t in _context.Trashes
                                       where t.ID == trash.ID
                                       select t).ToList();
                    trash.ID = ID;
                    _context.Trashes.Remove(removeTrash[0]);
                    _context.Trashes.Add(trash);
                    ID++;
                }


                _context.SaveChanges();
                return(true);
            }
        }
Exemplo n.º 2
0
        public static bool RefreshNote()
        {
            using (var _context = new DBSimpleNoteEntities())
            {
                var ID = 0;

                var noteList = (from n in _context.Notes.AsEnumerable()
                                select n)
                               .Select(x => new Note
                {
                    ID          = x.ID,
                    description = x.description,
                    dateCreated = x.dateCreated,
                    tags        = x.tags,
                    isPinned    = x.isPinned
                }).ToList();



                foreach (Note note in noteList)
                {
                    var removeNote = (from n in _context.Notes
                                      where n.ID == note.ID
                                      select n).ToList();
                    note.ID = ID;
                    _context.Notes.Remove(removeNote[0]);
                    _context.Notes.Add(note);
                    ID++;
                }


                _context.SaveChanges();
                return(true);
            }
        }
Exemplo n.º 3
0
 public static bool DeleteForever(Trash trash)
 {
     using (var _context = new DBSimpleNoteEntities())
     {
         _context.Trashes.Attach(trash);
         _context.Trashes.Remove(trash);
         _context.SaveChanges();
         return(true);
     }
 }
Exemplo n.º 4
0
 public static bool RemoveNote(Note note)
 {
     using (var _context = new DBSimpleNoteEntities())
     {
         _context.Notes.Attach(note);
         _context.Notes.Remove(note);
         _context.SaveChanges();
         return(true);
     }
 }
Exemplo n.º 5
0
        public static bool DeleteNote(User user, int id)
        {
            using (var _context = new DBSimpleNoteEntities())
            {
                var dbtask = (from u in _context.Notes
                              where u.ID == id && u.User_k == user.UserName
                              select u).SingleOrDefault();


                _context.Notes.Remove(dbtask);
                _context.SaveChanges();
                return(true);
            }
        }
Exemplo n.º 6
0
 public static bool AddTrash(Trash trash)
 {
     try
     {
         using (var _context = new DBSimpleNoteEntities())
         {
             _context.Trashes.Add(trash);
             _context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 7
0
 public static bool UpdateNote(Note note)
 {
     try
     {
         using (var _context = new DBSimpleNoteEntities())
         {
             _context.Notes.AddOrUpdate(note);
             _context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 8
0
 public static bool AddNote(Note note)
 {
     using (var _context = new DBSimpleNoteEntities())
     {
         var userdb = (from u in _context.Users
                       where u.UserName == note.User_k
                       select u).SingleOrDefault();
         if (userdb == null)
         {
             return(false);
         }
         else
         {
             _context.Notes.Add(note);
             _context.SaveChanges();
             return(true);
         }
     }
 }
Exemplo n.º 9
0
        public static bool MoveToLast(int ID)
        {
            using (var _context = new DBSimpleNoteEntities())
            {
                var newID = 0;

                var noteList = (from n in _context.Notes.AsEnumerable()
                                select n)
                               .Select(x => new Note
                {
                    ID          = x.ID,
                    description = x.description,
                    dateCreated = x.dateCreated,
                    tags        = x.tags,
                    isPinned    = x.isPinned
                }).ToList();

                foreach (Note note in noteList)
                {
                    var removeNote = (from n in _context.Notes
                                      where n.ID == note.ID
                                      select n).ToList();
                    if (note.ID == ID)
                    {
                        note.ID       = NoteController.GetListNote().Count - 1;
                        note.isPinned = false;
                        _context.Notes.Remove(removeNote[0]);
                        _context.Notes.Add(note);
                        continue;
                    }
                    note.ID = newID;
                    _context.Notes.Remove(removeNote[0]);
                    _context.Notes.Add(note);
                    RefreshNote();
                    newID++;
                }

                _context.SaveChanges();
                return(true);
            }
        }
Exemplo n.º 10
0
        public static bool SaveNote(Note note)
        {
            using (var _context = new DBSimpleNoteEntities())
            {
                var dbNote = (from u in _context.Notes
                              where u.ID == note.ID && u.User_k == note.User_k
                              select u).SingleOrDefault();
                dbNote.ID           = note.ID;
                dbNote.Title_Note   = note.Title_Note;
                dbNote.RichTextNote = note.RichTextNote;
                dbNote.Size         = note.Size;
                dbNote.Font         = note.Font;
                dbNote.ColorText    = note.ColorText;
                dbNote.ColorBg      = note.ColorBg;
                dbNote.User_k       = note.User_k;

                _context.Notes.AddOrUpdate(dbNote);
                _context.SaveChanges();
                return(true);
            }
        }