Assignment 3 - Retail Public Views and Stored Procedures
Modify VS's publish settings to publish "All files in project folder." This will copy your
source code to the server which will aid me in providing help and with grading.
In VS right-click on the project folder, select properties, Package/Publish Web,
items to deploy, "All files in this project folder."
- retail/index -
Listing categories: this exercise adds a layout view and category menu.
- All of the pages created in this assignment are public facing so their action methods
should be decorated with [AllowAnonymous]. Better yet, remove all of the authorization
from your project since it can make grading difficult.
- Layout: The retail store
needs a layout view to display the header, left menu, and anyother shared elements. The tutorial Layout View describes how to setup a layout page.
- CSS: Add a new stylesheet named retail.css and edit App_start/BundleConfig.cs to use it.
- Header: You can either create a custom header or modify the default navigation. The
navigation should at a minimum link to retail/index, retail/admin, and retail/about
- DataRepository: The category menu requires data from the database. Create a DataRepository
using Dapper as described in MIS
324 assignment 4 part 3 e-f. A good name would be "RetailRepository."
- Dapper needs a connection string in the web.config. Copy the LocalDB connection string from MIS 324 assignment 4 (near the bottom of the page) and add it to web.config. A good name would be "RetailStore".
Sql: The sql statement for listing categories needs to join the tables Category and ProductCategory
so that empty categories are not listed. The sample includes a count of items in each category
which is not required. Tip: Write Sql statements using VS's query designer. It provides Intellisense and testing. When finished cut-and-paste the quiery into the DataReposiory.
- Controller: Add an action method for _leftMenu that retrieves a list of categories.
- View: Add a new view _leftMenu.cshtml. Call it from the layout page with:
and add formatting (you may copy styles from the sample).
- retail/Category -
This exercise creates a page that lists the products in a category.
- DataRepository - Add a method named GetCategoryProducts(int catID) that takes a category ID and
returns the products in the category.
- Controller - Add a action method named Category that calls GetCategoyProducts(id).
- View: The index view has the appropriate layout so reuse it using this syntax:
public ActionResult Category(int id)
return View("index", retailRepository.GetCategoryProducts(id));
- retail/Search -
This exercise uses a stored procedure to search product titles.
- Left navigation: add a search textbox and button (you may copy html for the sample).
- Stored Procedure: Use VS Server Explorer to create a new stored procedure. The input
parameter is type varchar(50).
The following sql statement matches whole words starting with the query (it does not
match characters in the middle of words):
from Product p
where p.ItemName like @query + '%' or p.ItemName like '% ' + @query + '%'
order by p.ItemName;
- DataRepository: The first
example Is there a way to call a stored procedure with Dapper? shows how to call a stored procedure with Dapper.
- Controller: Add an action method named "Search" and populate
it with product information from the stored procedure. Display the count as shown here:
IEnumerable<Product> productList = retailRepository.Search(query);
ViewBag.message = productList.Count() + " products match '" + query + "'" ;
- View: Reuse the index view again. Add a ViewBag to display the number of items
found by the search.
- Controller. Also add the product count to Category.
- retail/about -
This page describes the site features. You may copy
the text from the sample or write your own.
- Display an image randomly selected from the database. This article shows
the syntax for retrieving
a single item with Dapper. The Detail view is a good template for displaying the image.
Submission instructions: Submit assignments via
the Canvas course management system.
Submit the full URL for each exercise in the assignment, listing the URLs
in the same order that they are listed in the assignment. To minimize typos in URLs
it is strongly recommended
that you copy the URLs from the address bar of the browser
rather than trying to type them. Incorrect URLs
will not be graded and no credit will be given.
When pages are connected via navigation it is only
necessary to submit the URL of the first page.