public int RemoveTagUsage <TUsage, TEntry>(long tagUsageId, IRepository <TEntry> repository) where TUsage : TagUsage { return(repository.HandleTransaction(ctx => { ctx.AuditLogger.SysLog(string.Format("deleting tag usage with Id {0}", tagUsageId)); var tagUsage = ctx.Load <TUsage>(tagUsageId); EntryPermissionManager.VerifyAccess(permissionContext, tagUsage.EntryBase, EntryPermissionManager.CanRemoveTagUsages); tagUsage.Delete(); ctx.Delete(tagUsage); ctx.Update(tagUsage.Tag); ctx.AuditLogger.AuditLog(string.Format("removed {0}", tagUsage)); ctx.AuditLogger.SysLog("Usage count for " + tagUsage.Tag + " is now " + tagUsage.Tag.UsageCount); return tagUsage.EntryBase.Id; })); }