public void AddPlaybackAction(PlaybackInfo play_info) { 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", play_info.Date.ToDateTimeParamValue()); statement.TryBind("@UserId", play_info.UserId); statement.TryBind("@ItemId", play_info.ItemId); statement.TryBind("@ItemType", play_info.ItemType); statement.TryBind("@ItemName", play_info.ItemName); statement.TryBind("@PlaybackMethod", play_info.PlaybackMethod); statement.TryBind("@ClientName", play_info.ClientName); statement.TryBind("@DeviceName", play_info.DeviceName); statement.TryBind("@PlayDuration", play_info.PlaybackDuration); statement.MoveNext(); } }, TransactionMode); } } }
public void UpdatePlaybackAction(PlaybackInfo play_info) { 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", play_info.Date.ToDateTimeParamValue()); statement.TryBind("@UserId", play_info.UserId); statement.TryBind("@ItemId", play_info.ItemId); statement.TryBind("@PlayDuration", play_info.PlaybackDuration); statement.MoveNext(); } }, TransactionMode); } } }