コード例 #1
0
 protected override bool SaveInstance(nDbRecord instance)
 {
     var item = (Note) instance;
     var rtn = false;
     try {
         var query = string.Format ("INSERT INTO {0} (Name, Value) VALUES (@Name, @Value); SELECT last_insert_rowid() as Id", NoteRepo.TABLE, item.Name, item.Value);
         item.Id = (int) _db.Connection.Query<long> (query, new { Name = item.Name, Value = item.Value }).Single();
         rtn = true;
     } catch (Exception e) {
         item.Errors.Add("", "Unable to save record", e);
     }
     return rtn;
 }
コード例 #2
0
        protected override bool DeleteInstance(nDbRecord instance)
        {
            if (instance == null) {
                nLog.Debug("Invalid request to delete a NULL db record of type Note");
                return false;
            }

            var item = (Note) instance;
            var rtn = false;
            try {
                var query = string.Format ("DELETE FROM {0} WHERE Id = @Id", NoteRepo.TABLE);
                nLog.Debug("Running delete SQL: " + query);
                _db.Connection.Execute (query, new { Id = item.Id });
                rtn = true;
            } catch (Exception e) {
                item.Errors.Add("", "Unable to delete record", e);
                nLog.Error("Failed", e);
            }
            return rtn;
        }