public void EditOperation(LatchOperation operation, IEnumerable <int> userIdsToAdd, IEnumerable <int> userIdsToRemove, IEnumerable <int> nodeIdsToAdd, IEnumerable <int> nodeIdsToRemove)
        {
            using (var scope = db.GetTransaction())
            {
                db.Update(operation);

                if (userIdsToAdd.Any())
                {
                    InsertLatchOperationUsers(userIdsToAdd.ToList(), operation.Id);
                }

                if (userIdsToRemove.Any())
                {
                    DeleteLatchOperationUsers(userIdsToRemove, operation.Id);
                }

                if (nodeIdsToAdd.Any())
                {
                    InsertLatchOperationNodes(nodeIdsToAdd.ToList(), operation.Id);
                }

                if (nodeIdsToRemove.Any())
                {
                    DeleteLatchOperationNodes(nodeIdsToRemove, operation.Id);
                }

                scope.Complete();
            }
        }
        public void InsertOperation(LatchOperation operation, IEnumerable <int> userIds, IEnumerable <int> nodeIds)
        {
            using (var scope = db.GetTransaction())
            {
                Insert(operation);

                if (userIds.Any())
                {
                    InsertLatchOperationUsers(userIds.ToList(), operation.Id);
                }

                if (nodeIds.Any())
                {
                    InsertLatchOperationNodes(nodeIds.ToList(), operation.Id);
                }

                scope.Complete();
            }
        }
        public void DeleteOperation(LatchOperation operation)
        {
            using (var scope = db.GetTransaction())
            {
                if (!operation.ApplyToAllUsers)
                {
                    var deleteUsersQuery = Sql.Builder
                                           .Append("DELETE FROM LatchOperationUser")
                                           .Where("LatchOperationId = @0", operation.Id);
                    db.Execute(deleteUsersQuery);
                }

                if (!operation.ApplyToAllNodes)
                {
                    var deleteNodesQuery = Sql.Builder
                                           .Append("DELETE FROM LatchOperationNode")
                                           .Where("LatchOperationId = @0", operation.Id);
                    db.Execute(deleteNodesQuery);
                }

                db.Delete(operation);
                scope.Complete();
            }
        }