public async Task Add(NoteInsertModel model, bool addRaw = false) { try { if (_key == null) { await SetKey(); } if (addRaw) { await _connection.InsertAsync(new Note { Modified = DateTime.Now, Text = model.Text, Title = model.Title, Version = 1, ExternalId = model.ExternalId }); } else { await _connection.InsertAsync(new Note { Modified = DateTime.Now, Text = SecureService.EncryptString(_key, model.Text), Title = SecureService.EncryptString(_key, model.Title), Version = 1, ExternalId = model.ExternalId }); } } catch (Exception ex) { throw new Exception("Database error: " + ex.Message); } }
public async Task Update(NoteUpdateModel model, bool updateRaw = false) { try { if (_key == null) { await SetKey(); } var note = await _connection.GetAsync <Note>(model.Id); if (updateRaw) { note.Text = model.Text; note.Title = model.Title; } else { note.Text = SecureService.EncryptString(_key, model.Text); note.Title = SecureService.EncryptString(_key, model.Title); } note.Modified = DateTime.Now; note.Version++; await _connection.UpdateAsync(note); } catch (Exception ex) { throw new Exception("Database error: " + ex.Message); } }