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); } }
public static bool getUser(string username, string password) { using (var _context = new DBSimpleNoteEntities()) { try { var user = (from u in _context.Users where u.UserName == username && u.Password == password select u.UserName).Single(); if (user == null) { return(false); } if (string.Compare(user.Trim(), username, false) == 0) { return(true); } return(false); } catch { return(false); } } }
public static List <Note> getAllNote(string _user) { using (var _context = new DBSimpleNoteEntities()) { var notes = (from u in _context.Notes.AsEnumerable() where u.User_k == _user // tìm giùm t cách load lên còn lại t đg coi lại khóa với lưu định dạng select new //u).ToList; { ID = u.ID, title = u.Title_Note, note = u.RichTextNote, size = u.Size, font = u.Font, colorBack = u.ColorBg, colorText = u.ColorText, user = u.User_k }) .Select(x => new Note { ID = x.ID, Title_Note = x.title, RichTextNote = x.note, Size = x.size, Font = x.font, ColorBg = x.colorBack, ColorText = x.colorText, User_k = x.user }); return(notes.ToList()); } }
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); } }
public static int getIDfromDB(string username) { using (var _context = new DBSimpleNoteEntities()) { var id = (from t in _context.Notes where t.User_k == username select t.ID).ToList(); if (id.Count <= 0) { return(1); } else { int i = 1; foreach (int ids in id) { if (ids != i) { return(i); } i++; } return(id.Max() + 1); } } }
public static bool DeleteForever(Trash trash) { using (var _context = new DBSimpleNoteEntities()) { _context.Trashes.Attach(trash); _context.Trashes.Remove(trash); _context.SaveChanges(); return(true); } }
public static bool RemoveNote(Note note) { using (var _context = new DBSimpleNoteEntities()) { _context.Notes.Attach(note); _context.Notes.Remove(note); _context.SaveChanges(); return(true); } }
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); } }
public static bool AddTrash(Trash trash) { try { using (var _context = new DBSimpleNoteEntities()) { _context.Trashes.Add(trash); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static bool UpdateNote(Note note) { try { using (var _context = new DBSimpleNoteEntities()) { _context.Notes.AddOrUpdate(note); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static Trash GetTrash(int ID) { using (var _context = new DBSimpleNoteEntities()) { var trash = (from t in _context.Trashes where t.ID == ID select t).ToList(); if (trash.Count == 1) { return(trash[0]); } else { return(null); } } }
public static Note GetNote(int ID) { using (var _context = new DBSimpleNoteEntities()) { var note = (from n in _context.Notes where n.ID == ID select n).ToList(); if (note.Count == 1) { return(note[0]); } else { return(null); } } }
public static List <Note> GetListNote() { using (var _context = new DBSimpleNoteEntities()) { var note = (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(); return(note); } }
public static List <Trash> GetListTrash() { using (var _context = new DBSimpleNoteEntities()) { var trash = (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(); return(trash); } }
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); } } }
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); } }
public static List <Note> getlistNote(string searchTitle, string user) { using (var _context = new DBSimpleNoteEntities()) { var Note = (from u in _context.Notes.AsEnumerable() where u.User_k == user && u.Title_Note.Contains(searchTitle) select u) .Select(x => new Note { ID = x.ID, Title_Note = x.Title_Note, RichTextNote = x.RichTextNote, Size = x.Size, Font = x.Font, ColorBg = x.ColorBg, ColorText = x.ColorText, User_k = x.User_k }).ToList(); return(Note); } }
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); } }