Adding logic to Business Object

Adding logic to Business Object

Old forum URL: forums.lhotka.net/forums/t/5681.aspx


AndyW posted on Monday, October 27, 2008

 

I have a BusinessBaseList bound to a Grid control, one of the columns is a check box.  Only one row can can have a tick in the checkbox, so if a user puts a tick in another row, the previous checked row must have the value removed.

I have currently got this working by looping around the row collection of the grid and setting all rows other then the newly checked to unchecked.

Although this is working, our next stage is to create a web front end as well as the windows version.

So we really need this logic in the business object, what would be the best way to achieve this? 

Thanks

sergeyb replied on Monday, October 27, 2008

The easiest way is probably a business rule.  In the rule check the new value, and if it is try, loop through all other rows in parent list and set them to false( if they are true).

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: AndyW [mailto:cslanet@lhotka.net]
Sent: Monday, October 27, 2008 10:58 AM
To: Sergey Barskiy
Subject: [CSLA .NET] Adding logic to Business Object

 

 

I have a BusinessBaseList bound to a Grid control, one of the columns is a check box.  Only one row can can have a tick in the checkbox, so if a user puts a tick in another row, the previous checked row must have the value removed.

I have currently got this working by looping around the row collection of the grid and setting all rows other then the newly checked to unchecked.

Although this is working, our next stage is to create a web front end as well as the windows version.

So we really need this logic in the business object, what would be the best way to achieve this? 

Thanks



AndyW replied on Tuesday, November 11, 2008

Thanks Sergey,

I have it working in most part, but I do not know how to get the value of the child object that has changed.

For instance everytime a checkbox is clicked the Custom Rule is fired and sets all the checkboxes to false, however I am unsure of how to ignore the child row that has changed.

Here is my custom validation rule that is set in the parent object.

private static bool IsHomepageCheck<T>(T target, Csla.Validation.RuleArgs e) where T : Article
{
      
foreach (ArticleImage artImg in target._articleImages)
      {
            
artImg.IsHomepage = false;
      }

      return true;
}

As you can see I am setting all the items to false, but I need to ignore the item that has been changed.

Thanks

Andy

sergeyb replied on Tuesday, November 11, 2008

I think you would need the Equals check and move the rule to articleImage level

private static bool IsHomepageCheck<T>(T target, Csla.Validation.RuleArgs e) where T : ArticleImage
{
      foreach (ArticleImage artImg in (ArticleImageList)target.Parent))
      {
            If (!(artImg.Equals(target) && artImg.IsHomepage == true)

            artImg.IsHomepage = false;
      }

      return true;
}

 

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: AndyW [mailto:cslanet@lhotka.net]
Sent: Tuesday, November 11, 2008 8:09 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: Adding logic to Business Object

 

Thanks Sergey,

I have it working in most part, but I do not know how to get the value of the child object that has changed.

For instance everytime a checkbox is clicked the Custom Rule is fired and sets all the checkboxes to false, however I am unsure of how to ignore the child row that has changed.

Here is my custom validation rule that is set in the parent object.

private static bool IsHomepageCheck<T>(T target, Csla.Validation.RuleArgs e) where T : Article
{
      foreach (ArticleImage artImg in target._articleImages)
      {
            artImg.IsHomepage = false;
      }

      return true;
}

As you can see I am setting all the items to false, but I need to ignore the item that has been changed.

Thanks

Andy



AndyW replied on Wednesday, November 12, 2008

Thanks Sergey, all is now working, much appreciated :-)

 

rsbaker0 replied on Wednesday, November 12, 2008

I could be wrong, but I see potential problems with that implementation if you were ever to call check rules manually on an object in the child list. It looks like it would unconditionally set any existing IsHomePage value in the list that was true to false.

Copyright (c) Marimer LLC