Ejemplo n.º 1
0
        public async Task <Usernote> GetNoteAsync(int key)
        {
            if (_db == null)
            {
                _db = new UsernoteContext();
            }
            await _db.Database.EnsureCreatedAsync();

            return(await _db.Notes.FirstOrDefaultAsync(x => x.Key == key));
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <Usernote> > GetNotesForUserAsync(ulong userId)
        {
            if (_db == null)
            {
                _db = new UsernoteContext();
            }
            await _db.Database.EnsureCreatedAsync();

            return(_db.Notes.Where(x => x.SubjectId == userId));
        }
Ejemplo n.º 3
0
        public async Task ClearNotesAsync(ulong userId)
        {
            if (_db == null)
            {
                _db = new UsernoteContext();
            }
            await _db.Database.EnsureCreatedAsync();

            var toRemove = _db.Notes.Where(x => x.SubjectId == userId);

            _db.Notes.RemoveRange(toRemove);
            await _db.SaveChangesAsync();
        }
Ejemplo n.º 4
0
        public async Task <bool> RemoveNoteAsync(int key)
        {
            if (_db == null)
            {
                _db = new UsernoteContext();
            }
            await _db.Database.EnsureCreatedAsync();

            if (!await _db.Notes.AnyAsync(x => x.Key == key))
            {
                return(false);
            }
            _db.Notes.Remove(await _db.Notes.FirstOrDefaultAsync(x => x.Key == key));
            await _db.SaveChangesAsync();

            return(true);
        }
Ejemplo n.º 5
0
        public async Task AddNoteAsync(ulong userId, ulong authorId, ulong timestamp, string content)
        {
            if (_db == null)
            {
                _db = new UsernoteContext();
            }
            await _db.Database.EnsureCreatedAsync();

            await _db.Notes.AddAsync(new Usernote
            {
                SubjectId     = userId,
                AuthorId      = authorId,
                UnixTimestamp = timestamp,
                Content       = content
            });

            await _db.SaveChangesAsync();
        }
Ejemplo n.º 6
0
 public void DisposeContext()
 {
     _db.Dispose();
     _db = null;
 }