Databases Reference
In-Depth Information
context.FulfillOrder(orderId);
context.SaveChanges();
transaction.Complete();
}
Invoking Business Rules in Web Applications
Out of the box, Dynamic Data does not provide a way to invoke a custom business rule
method from a dynamically generated page. Instead, you need to create a custom page or
a custom page template and write code to call the method explicitly. Listing 9.3 shows
markup of a custom page that displays an Order entity in a read-only FormView control,
with a Fulfill button that users can click to mark the order as fulfilled.
LISTING 9.3 Custom Order Page with Fulfill Button (Markup)
<%@ Page Language=”C#”
MasterPageFile=”~/Site.master” CodeBehind=”SamplePage.aspx.cs”
Inherits=”WebApplication.Samples.Ch9.EntityMethod.SamplePage” %>
<asp:Content ContentPlaceHolderID=”main” runat=”server”>
<h2>Entry from table <%= ordersTable.DisplayName %></h2>
<asp:ValidationSummary runat=”server” />
<unl:UnleashedValidator runat=”server” ID=”validator”
ControlToValidate=”formView” Display=”None”/>
<asp:FormView runat=”server” ID=”formView” DataSourceID=”dataSource”
DataKeyNames=”OrderID”>
<ItemTemplate>
<asp:DynamicEntity runat=”server” />
<tr><td colspan=”2”>
<asp:Button runat=”server” Text=”Fulfill” OnClick=”FulfillButton_Click” />
</td></tr>
</ItemTemplate>
</asp:FormView>
<asp:EntityDataSource ID=”dataSource” runat=”server”
ConnectionString=”name=NorthwindEntities”
DefaultContainerName=”NorthwindEntities” EntitySetName=”Orders” />
<asp:QueryExtender TargetControlID=”dataSource” runat=”server”>
<asp:DynamicRouteExpression />
</asp:QueryExtender>
</asp:Content>
Most of the code in Listing 9.3 is very similar to the Details page template discussed in
Chapter 6, “Page Templates.” (In fact, you could have created it as a custom page template
for the Order entity.) The only notable difference here is the Fulfill button, which replaced
 
 
Search WWH ::




Custom Search