New Posts New Posts RSS Feed: Interceptors not fired for changes made in AfterSet interceptor
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Interceptors not fired for changes made in AfterSet interceptor

 Post Reply Post Reply
Author
Sinnema View Drop Down
Groupie
Groupie
Avatar

Joined: 23-Mar-2009
Location: Muri AG, EU, CH
Posts: 54
Post Options Post Options   Quote Sinnema Quote  Post ReplyReply Direct Link To This Post Topic: Interceptors not fired for changes made in AfterSet interceptor
    Posted: 09-Sep-2009 at 6:03am
Hi,
 
We've created the following, very simple, code to reset booleans in other rows of a Navigation Property. The functionality should be like this:
- We have several Addresses but only 1 can be the Postal Address
- Each Address has an IsPostal boolean which tells if this Address is the Postal Address
- When a IsPostal for an Address is set to true, all others should be disabled automatically
 
The code below works fine. The booleans for the other items are realy set to false but the Interceptors which are coupled to these properties are not fired. This behavior prevent our mask to be updated with the new values.
 
Regards,
Paul Sinnema
Diartis AG
 
  [AfterSet(EntityPropertyNames.IsPostal)]
  public void AfterSetIsPostal(PropertyInterceptorArgs<Address, Boolean> args)
  {
   ResetIsPostal(args);
  }
 
  private void ResetIsPostal(PropertyInterceptorArgs<Address, Boolean> args)
  {
   if (args.Value)
   {
    foreach (var item in this.Contact.AddressList.Where(address => !address.Equals(this)))
    {
     if (item.IsPostal)
     {
      item.IsPostal = false;
     }
    }
   }
  }


Edited by Sinnema - 09-Sep-2009 at 6:04am
Back to Top
Sinnema View Drop Down
Groupie
Groupie
Avatar

Joined: 23-Mar-2009
Location: Muri AG, EU, CH
Posts: 54
Post Options Post Options   Quote Sinnema Quote  Post ReplyReply Direct Link To This Post Posted: 09-Sep-2009 at 6:48am
Hi,
 
We've solved it as shown below. Is that really the way to solve this? I would hate it to have to write that much code for each set of the same property in other Items. We noticed that when we set another property (i.e. not the property that is changing now) then the value is set correctly and it's interceptor is fired too.
 
Regards,
Paul Sinnema.
Diartis AG
 
  [AfterSet(EntityPropertyNames.IsPostal)]
  public void AfterSetIsPostal(PropertyInterceptorArgs<Address, Boolean> args)
  {
   ResetIsPostal(args);
  }
  private void ResetIsPostal(PropertyInterceptorArgs<Address, Boolean> args)
  {
   if (args.Value)
   {
    foreach (var item in this.Contact.AddressList.Where(address => !address.Equals(this)))
    {
     if (item.IsPostal)
     {
      item.IsPostal = false;
      FireIsPostalSetters(item, false);
     }
    }
   }
  }
  private void FireIsPostalSetters(Address address, bool value)
  {
   var actions = Address.IsPostalEntityProperty.SetterInterceptor.GetActions();
   var args = new DataEntityPropertySetInterceptorArgs<Address, Boolean>(Address.IsPostalEntityProperty, address, null);
   args.Value = value;
   foreach (var item in actions)
   {
    item.Action(args);
   }
  }
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down