Papa Bob's Mega Solution Part 9 - Creating the Order Management Page

Tutorial Series: Free C# Fundamentals via ASP.NET Web Apps

Previous Article

This is the ninth and final part of the solution for Papa Bob's Mega Challenge. In this part, we're going to add the OrderManagement page and display the Orders via a GridView.

Step 1: Add the OrderManagement Page

The requirements for this challenge specify that a page should be added that allows the employees of Papa Bob's to see the uncompleted orders in a GridView. In order to do this, we'll need to add a separate Web Form in the Presentation layer called OrderManagement:


Inside OrderManagement.aspx, we'll need to add a header and a GridView control called 'ordersGridView':


Step 2: Getting a List of Orders

This GridView will need to be populated with a list of orders passed from the Domain layer. To create this functionality, navigate to OrderManager.cs and create a new method called GetOrders(). Because the orders themselves are stored in the Persistence layer, this method will return the result of a GetOrders() method in the Persistence layer:


Generate a method stub for GetOrders() in the Persistence layer and navigate to it. Inside, write the following code to get a reference to the orders stored in the database:


Now that we have a reference to the original set of orders, we need to convert them to a list of OrderDTO orders. To do that, create a new helper method called convertToDTO() that returns this list:


Because a List<\Order> is supplied, we can use a foreach() loop to iterate through that collection and convert each individual entry to a DTO object:


Inside this loop, create a new DTO.OrderDTO object and populate its properties with the properties of the original order, then and add it to the ordersDTO collection:


Finally, return ordersDTO at the end of the method. Return to the GetOrders() method and create a new variable called ordersDTO. Assign that variable the returned value of the convertToDTO() method:


Step 3: Determining Completed Orders

Part of the requirement of this challenge is to create a button inside the GridVie that the workers of Papa Bob's can press to hide (but not delete) the orders that have been completed. These orders remain in the database, but are no longer displayed on the GridView. To create this functionality, we'll add a new property to the Orders table. Call this property 'Completed', and give it a bit value type defaulted to 0:


Update the database to commit the changes. Then, navigate to PapaBobsEntities.edmx in the Persistence layer. Right-click anywhere and select 'Update Model from Database' and choose to refresh the Orders Table:


This will add the Completed property to the Entity Model of Order. We'll need to also add this property to the OrderDTO class:


Step 4: Displaying Orders

Return to the GetOrders() method in the OrderRepository and make the following changes to filter the orders that will be returned:


This simply tells the compiler only to gather the orders that have a Completed value set to false. This way, no completed orders will make it to the GridView in OrderManagement.

Navigate to OrderManagement.aspx.cs and write the following code to create a variable called orders, set to the returned value of the Domain layer's GetOrders() method. Then, set that variable as the GridView's data source:


Run your application, submit some orders, then navigate to OrderManagement.aspx to see the following result:


Step 5: Adding the Complete Button to the GridView

The final step in this challenge is to create a hyperlink button that, when clicked, completes the order, hiding it from the GridView. To begin, go to OrderManagement.aspx and in the Design view, click on the GridView and select 'Edit Columns...':


From the resulting dialog, add a ButtonField with its text property set to "Complete":


Now, in the Properties window of the GridView, double click on RowCommand to generate a new event:


Step 6: Hiding the Order from GridView

Navigate to the generated RowCommand event and type in the following code to determine which row's button was clicked:


This code converts the event argument (which row number) to an integer and stores the value in an index. Then, that row from the ordersGridView is assigned to a new GridViewRow object so we can reference it directly.

Next, we need to determine the OrderID of the order belonging to that row so we can pass it to the database. We'll do this by accessing the second cell of that row (which has the OrderId) and assigning that to a new variable:


We'll now parse this value back into a GUID and pass it to the Domain layer in a new method called CompleteOrder():


Generate a method stub for CompleteOrder() and locate it within the OrderManager class. Within that method, make a call to a new method in the OrderRepository called CompleteOrder() passing in the orderId:


Generate a method stub once again and locate it within the OrderRepository. This method will create a new instance of PapaBobsDbEntities and locate the order located in the Orders table with the matching orderId:


Once the order is located, it will set its Completed value to true and save the changes to the database:


Now, return to OrderManagement.aspx.cs to ensure that the page refreshes after the button has been pressed. To do this, cut and paste the code from the Page_Load into a new method called refreshGridView():


Finally, call this method in both the RowCommand and Page_Load to get the GridView data the first time the page loads and each time an order is completed:



Save and run your project, add some orders and navigate to OrderManagement to see the working result:

Initial Page


Order Completed


Database Result



This concludes the entire solution of Papa Bob's Mega Challenge. This was by far the longest and most detailed of all the challenges in this course. If you had difficulty completing this challenge, come back to it later and try to implement the concepts applied in this solution. Make it your own and do your best. Continue struggling with it until you can successfully complete it. You'll learn a lot in the process. Upon completing this challenge, you've successfully completed the C# Fundamentals Via ASP.NET Web Forms course! Congratulations on creating your very own website! Continue using these concepts and build upon them to continue learning new skills as a web developer. You've done a great job in this course, keep it up!

Related Articles in this Tutorial:

Lesson 1 - Series Introduction

Lesson 2 - Installing Visual Studio 2015

Lesson 3 - Building Your First Web App

Lesson 4 - Understanding What You Just Did

Lesson 5 - Working with Projects in Visual Studio

Lesson 6 - Simple Web Page Formatting in Visual Studio

Challenge 1

Solution 1

Lesson 7 - Variables and Data Types

Lesson 8 - Data Type Conversion

Lesson 9 - Arithmetic Operators

Lesson 10 - C# Syntax Basics

Challenge 2 - ChallengeSimpleCalculator

Solution - ChallengeSimpleCalculator

Lesson 11 - Conditional If Statements

Lesson 12 - The Conditional Ternary Operator

Challenge 3 - ChallengeConditionalRadioButton

Solution - Challenge Conditional RadioButton

Lesson 13 - Comparison and Logical Operators

Lesson 13 Challenge - First Papa Bob's Website

Solution - Challenge First Papa Bob's Website

Lesson 14 - Working with Dates and Times

Lesson 15 - Working With Spans of Time

Lesson 16 - Working with the Calendar Server Control

Challenge 4 - Challenge Days Between Dates

Solution - Challenge Days Between Dates

Lesson 17 - Page_Load and Page.IsPostBack

Lesson 18 - Setting a Break Point and Debugging

Lesson 19 - Formatting Strings

Challenge 5 - Challenge Epic Spies Assignment

Solution - Challenge Epic Spies Assignment

Lesson 20 - Maintaining State with ViewState

Lesson 21 - Storing Values in Arrays

Lesson 22 - Understanding Multidimensional Arrays

Lesson 23 - Changing the Length of an Array

Challenge 6 - Challenge Epic Spies Asset Tracker

Solution - Challenge Epic Spies Asset Tracker

Lesson 24 - Understanding Variable Scope

Lesson 25 - Code Blocks and Nested If Statements

Lesson 26 - Looping with the For Iteration Statement

Challenge 7 - Challenge For Xmen Battle Count

Solution - Challenge For Xmen Battle Count

Lesson 27 - Looping with the while() & do...while() Iteration Statements

Lesson 28 - Creating and Calling Simple Helper Methods

Lesson 29 - Creating Methods with Input Parameters

Lesson 30 - Returning Values from Methods

Lesson 31 - Creating Overloaded Methods

Lesson 32 - Creating Optional Parameters

Lesson 33 - Creating Names Parameters

Lesson 34 - Creating Methods with Output Parameters

Challenge 8 - Challenge Postal Calculator Helper Methods

Solution - Challenge Postal Calculator Helper Methods

Mega Challenge Casino

Solution - Mega Challenge Casino

Lesson 35 - Manipulating Strings

Challenge 9 - Phun With Strings

Solution - Challenge Phun With Strings

Lesson 36 - Introduction to Classes and Objects

Challenge - Hero Monster Classes Part 1

Solution - Hero Monster Classes Part 1

Challenge - Hero Monster Classes Part 2

Solution - Challenge Hero Monster Classes Part 2

Lesson 37 - Creating Class Files Creating Cohesive Classes and Code Navigation

Lesson 38 - Understanding Object References and Object Lifetime

Lesson 39 - Understanding the .NET Framework and Compilation

Lesson 40 - Namespaces and Using Directives

Lesson 41 - Creating Class Libraries and Adding References to Assemblies

Lesson 42 - Accessibility Modifiers, Fields and Properties

Lesson 43 - Creating Constructor Methods

Lesson 44 - Naming Conventions for Identifiers

Lesson 45 - Static vs Instance Members

Challenge 10 - Challenge Simple Darts

Solution - Challenge Simple Darts

Lesson 46 - Working with the List Collection

Lesson 47 - Object Initializers

Lesson 48 - Collection Initializers

Lesson 49 - Working with the Dictionary Collection

Lesson 50 - Looping with the foreach Iteration Statement

Lesson 51 - Implicitly-Typed Variables with the var Keyword

Challenge 11 - Challenge Student Courses

Solution - Challenge Student Courses

Mega Challenge War

Solution - Mega Challenge War

Lesson 52 - Creating GUIDs

Lesson 53 - Working with Enumerations

Lesson 54 - Understanding the switch() Statement

Lesson 55 - First Pass at the Separation of Concerns Principle

Lesson 56 - Understanding Exception Handling

Lesson 57 - Understanding Global Exception Handling

Lesson 58 - Understanding Custom Exceptions

Lesson 59 - Creating a Database in Visual Studio

Lesson 60 - Creating an Entity Data Model

Lesson 61 - Displaying the DbSet Result in an ASP.NET GridView

Lesson 62 - Implementing a Button Command in a GridView

Lesson 63 - Using a Tools-Centric Approach to Building a Database Application

Lesson 64 - Using a Maintenance-Driven Approach to Building a Database Application

Lesson 65 - Creating a New Instance of an Entity and Persisting it to the Database

Lesson 66 - Package Management with NuGet

Lesson 67 - NuGet No-Commit Workflow

Lesson 68 - Introduction the Twitter Bootstrap CSS Framework

Lesson 69 - Mapping Enum Types to Entity Properties in the Framework Designer

Lesson 70 - Deploying the App to Microsoft Azure Web Services Web Apps

Papa Bob's Mega Challenge

Papa Bob's Mega Solution Part 1 - Setting up the Solution

Papa Bob's Mega Solution Part 2 - Adding an Order to the Database

Papa Bob's Mega Solution Part 3 - Passing an Order from the Presentation Layer

Papa Bob's Mega Solution Part 4 - Creating the Order Form

Papa Bob's Mega Solution Part 5 - Adding Enums

Papa Bob's Mega Solution Part 6 - Creating an Order with Validation

Papa Bob's Mega Solution Part 7 - Calculating the Order Price

Papa Bob's Mega Solution Part 8 - Displaying the Price to the User

Papa Bob's Mega Solution Part 9 - Creating the Order Management Page


Please login or register to add a comment