var ext = PhoneSystem.Root.GetDNByNumber(strExtNr) as Extension;
var profile=ext.FwdProfiles.Where( x => x.Name == "Out of office").First(); // 'Available', 'Away', 'Out of office', 'Custom 1', 'Custom 2', maybe parameter?
if( profile != null ) {
// DestinationStruct need 3 parameter
// 1 DestinationType: 'None', 'VoiceMail', 'Extension', 'Queue', 'RingGroup', 'IVR', 'External', 'Fax', 'Boomerang' (external number),
// 'Deflect', 'VoiceMailOfDestination', 'Callback' (reserved), 'RoutePoint'
// 2 internal DN, maybe select by parameter - OR -
// 3 external number as string, maybe select by parameter
var dest = new DestinationStruct();
dest.To=DestinationType.Extension;
dest.Internal=PhoneSystem.Root.GetDNByNumber(strDestNr); // needed if internal destination
// dest.External=strDestNr; // needed if external destination
if( profile.TypeOfRouting == RoutingType.Available) {
var route=profile.AvailableRoute; // maybe select by parameter?
route.NoAnswer.AllCalls = dest;
route.NoAnswer.Internal = dest;
route.Busy.AllCalls = route.NotRegistered.AllCalls = dest;
route.Busy.Internal = route.NotRegistered.Internal = dest;
}
if( profile.TypeOfRouting == RoutingType.Away) {
var route=profile.AwayRoute;
var external = profile.AwayRoute.External;
route.Internal.AllHours = dest; // maybe select by parameter?
route.Internal.OutOfOfficeHours = dest;
route.External.AllHours = dest;
route.External.OutOfOfficeHours = dest;
}
ext.Save();
}