public bool Update(Pulse entity) { using (logger.BeginScope(nameof(this.Update))) { if (entity == null) { logger.LogWarning("ArgumentNullException while updating pulse in DB"); return false; } using (var context = new PsqlContext()) { try { DbPulse dbPulse = entity.ToDbEntity(); context.Pulse.Update(dbPulse); context.SaveChanges(); logger.LogDebug("Pulse updated successfully"); return true; } catch (Exception e) { logger.LogWarning(e.ToString() + " while updating pulse in DB"); return false; } } } }
internal static Pulse ToDomainEntity(this DbPulse entity) { Pulse pulse = new Pulse { SessionID = entity.SessionId, BPM = entity.Bpm, TimeStamp = DateTime.SpecifyKind(entity.timestamp, DateTimeKind.Utc) }; return(pulse); }
internal static DbPulse ToDbEntity(this Pulse entity) { DbPulse pulse = new DbPulse { SessionId = entity.SessionID, Bpm = entity.BPM, timestamp = entity.TimeStamp }; return(pulse); }