public bool IsAllowed(Customer customer, string operation) { DetachedCriteria criteria = DetachedCriteria.For<CustomerOperation>() .Add(Expression.Eq("Customer", customer)) .CreateCriteria("Operation") .Add(Expression.Eq("Name", operation)); ICollection<CustomerOperation> operations = repository.FindByCriteria<CustomerOperation>(criteria); if (operations.Count == 0) { logger.Log(string.Format("Permission denied: customer {0} for {1}", customer.Name, operation)); return false; } else { logger.Log("Has permission on " + customer.Name + " to " + operation); return true; } }
private static void ConfigureDatabase() { ActiveRecordStarter.Initialize( InPlaceConfigurationSource.BuildForMSSqlServer("localhost", "test"), typeof(Customer), typeof(CustomerOperation), typeof(Operation)); ActiveRecordStarter.CreateSchema(); Customer customer = new Customer(); customer.Name = "oren"; ActiveRecordMediator.Save(customer); Operation op = new Operation(); op.Name = "View"; ActiveRecordMediator.Save(op); CustomerOperation co = new CustomerOperation(); co.Customer = customer; co.Operation = op; ActiveRecordMediator.Save(co); }