Esempio n. 1
0
        public async Task <List <NoteGetModel> > Get(bool getRaw = false)
        {
            try
            {
                if (_key == null)
                {
                    await SetKey();
                }
                var notes = await _connection.Table <Note>().ToListAsync();

                var notesGetModel = new List <NoteGetModel>();
                foreach (var note in notes)
                {
                    if (getRaw)
                    {
                        notesGetModel.Add(new NoteGetModel
                        {
                            ExternalId = note.ExternalId,
                            Id         = note.Id,
                            Modified   = note.Modified,
                            Text       = note.Text,
                            Title      = note.Title,
                            Version    = note.Version
                        });
                    }
                    else
                    {
                        notesGetModel.Add(new NoteGetModel
                        {
                            ExternalId = note.ExternalId,
                            Id         = note.Id,
                            Modified   = note.Modified,
                            Text       = SecureService.DecryptString(_key, note.Text),
                            Title      = SecureService.DecryptString(_key, note.Title),
                            Version    = note.Version
                        });
                    }
                }
                return(notesGetModel);
            }
            catch (Exception ex)
            {
                throw new Exception("Database error: " + ex.Message);
            }
        }
Esempio n. 2
0
        public async Task <NoteGetModel> Get(int id)
        {
            try
            {
                if (_key == null)
                {
                    await SetKey();
                }
                var note = await _connection.GetAsync <Note>(id);

                return(new NoteGetModel
                {
                    ExternalId = note.ExternalId,
                    Id = note.Id,
                    Modified = note.Modified,
                    Text = SecureService.DecryptString(_key, note.Text),
                    Title = SecureService.DecryptString(_key, note.Title)
                });
            }
            catch (Exception ex)
            {
                throw new Exception("Database error: " + ex.Message);
            }
        }