public void AddPlaybackAction(PlaybackInfo playInfo) { string sql_add = "insert into PlaybackActivity " + "(DateCreated, UserId, ItemId, ItemType, ItemName, PlaybackMethod, ClientName, DeviceName, PlayDuration) " + "values " + "(@DateCreated, @UserId, @ItemId, @ItemType, @ItemName, @PlaybackMethod, @ClientName, @DeviceName, @PlayDuration)"; using (WriteLock.Write()) { using var connection = CreateConnection(); connection.RunInTransaction(db => { using var statement = db.PrepareStatement(sql_add); statement.TryBind("@DateCreated", playInfo.Date.ToDateTimeParamValue()); statement.TryBind("@UserId", playInfo.UserId); statement.TryBind("@ItemId", playInfo.ItemId); statement.TryBind("@ItemType", playInfo.ItemType); statement.TryBind("@ItemName", playInfo.ItemName); statement.TryBind("@PlaybackMethod", playInfo.PlaybackMethod); statement.TryBind("@ClientName", playInfo.ClientName); statement.TryBind("@DeviceName", playInfo.DeviceName); statement.TryBind("@PlayDuration", playInfo.PlaybackDuration); statement.MoveNext(); }, TransactionMode); } }
public void UpdatePlaybackAction(PlaybackInfo playInfo) { string sql_add = "update PlaybackActivity set PlayDuration = @PlayDuration where DateCreated = @DateCreated and UserId = @UserId and ItemId = @ItemId"; using (WriteLock.Write()) { using var connection = CreateConnection(); connection.RunInTransaction(db => { using var statement = db.PrepareStatement(sql_add); statement.TryBind("@DateCreated", playInfo.Date.ToDateTimeParamValue()); statement.TryBind("@UserId", playInfo.UserId); statement.TryBind("@ItemId", playInfo.ItemId); statement.TryBind("@PlayDuration", playInfo.PlaybackDuration); statement.MoveNext(); }, TransactionMode); } }