public static void MapToEntity(this AdminRuleDetailsModel model, RuleConfiguration rule)
        {
            if (model.RuleId.HasValue)
            {
                rule.RuleId = model.RuleId.Value;
            }

            rule.Name = model.Name;
            rule.Type = model.Type;

            switch (model.Type)
            {
            case RuleType.DateRange:
                (model as DateRangeRuleModel).MapToEntity(rule as DateRangeRuleConfiguration);
                break;

            case RuleType.EventDuration:
                (model as EventDurationRuleModel).MapToEntity(rule as EventDurationRuleConfiguration);
                break;

            case RuleType.EventGroup:
                (model as EventGroupRuleModel).MapToEntity(rule as EventGroupRuleConfiguration);
                break;

            case RuleType.MinimumDate:
                (model as MinimumDateRuleModel).MapToEntity(rule as MinimumDateRuleConfiguration);
                break;

            case RuleType.Weekly:
                (model as WeeklyRuleModel).MapToEntity(rule as WeeklyRuleConfiguration);
                break;

            case RuleType.BookingTimeOverride:
                (model as BookingTimeOverrideRuleModel).MapToEntity(rule as BookingTimeOverrideRuleConfiguration);
                break;

            case RuleType.MultipleBooking:
                (model as MultipleBookingRuleModel).MapToEntity(rule as MultipleBookingRuleConfiguration);
                break;

            default:
                throw new InvalidOperationException(String.Format("Rule of type '{0}' not yet configured!", model.Type));
            }
        }
        public static void InitializeFor(this AdminRuleDetailsModel model, RuleType type)
        {
            switch (model.Type)
            {
            case RuleType.MinimumDate:
                // Nothing to do here so far...
                break;

            case RuleType.Weekly:
                (model as WeeklyRuleModel).AvailableEvents = Database.Instance.GetActiveEvents();
                break;

            case RuleType.DateRange:
                (model as DateRangeRuleModel).AvailableEvents = Database.Instance.GetActiveEvents();
                break;

            case RuleType.EventDuration:
                (model as EventDurationRuleModel).AvailableEvents = Database.Instance.GetActiveEvents();
                break;

            case RuleType.EventGroup:
                (model as EventGroupRuleModel).AvailableEvents = Database.Instance.GetActiveEvents();
                break;

            case RuleType.BookingTimeOverride:
                (model as BookingTimeOverrideRuleModel).AvailableEvents = Database.Instance.GetActiveEvents();
                break;

            case RuleType.MultipleBooking:
                (model as MultipleBookingRuleModel).AvailableEvents = Database.Instance.GetActiveEvents();
                break;

            default:
                throw new InvalidOperationException(String.Format("Rule of type '{0}' not yet configured!", model.Type));
            }
        }