BusinessProcessDeleteRowAfterLeavingItIf Method

Sets an expression that determines if the current row will be deleted once left.

Definition

Namespace: Firefly.Box
Assembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
C#
public void DeleteRowAfterLeavingItIf(
	Func<bool> condition
)

Parameters

condition  FuncBoolean
 

Remarks

Notice that when the expression evaluates to true, the LeaveRow event will execute a second time (the first one was when the row was left), this time with Delete Activity property

Example

This example demonstrates the usage of DeleteRowAfterLeavingIt
This example is in the form of Unit Tests. It references the NUnit framework. This framework can be downloaded from www.NUnit.org. For more information about unit testing visit: www.NUnit.org.
This example is based on test data. The code for the entities included in this test data can be found in the documentation of Entity
C#
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Firefly.Box;
using Firefly.Box.Testing;

namespace TestFirefly.Box.Documentation
{
    [TestFixture]
    public class DeleteRowAfterLeavingIt
    {
        [Test]
        public void Demo()
        {
            var employees = new Pubs.Employees();
            employees.InitializeWithTestData();// Insert test data to the table
            employees.CountRows().ShouldBe(43);// Verifies that the test data has 43 rows

            var bp = new BusinessProcess
                         {
                             From = employees
                         };
            bp.DeleteRowAfterLeavingItIf(() => employees.MiddleInitial == "");// Settings the Delete row condition


            int numberOfLeaveRowInUpdateActivity = 0;
            int numberOfLeaveRowInDeleteActivity = 0;
            int numberOfLeaveRowExecutions = 0;
            bp.LeaveRow += ()=>
                               {
                                   if (bp.Activity == Activities.Update)//Counting executions for update activity
                                   {
                                       numberOfLeaveRowInUpdateActivity++;
                                   }
                                   if (bp.Activity == Activities.Delete)//Counting executions for Delete activity
                                   {
                                       numberOfLeaveRowInDeleteActivity++;
                                   }
                                   numberOfLeaveRowExecutions++;
                               };
            bp.Run();
            numberOfLeaveRowInUpdateActivity.ShouldBe(43);//The leave row was executed once for each employee in update mode
            numberOfLeaveRowInDeleteActivity.ShouldBe(10);//The leave row was executed again for the 10 employees that matches the condition
            numberOfLeaveRowExecutions.ShouldBe(53);//The leave row was executed a total of 53 times.
        }
    }
}

See Also