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."
- Configure Authentication: The WebAPI project type used in assignment 1 does not support individual user accounts. In this step you will modify your project to use them. Steps:
- Make a backup copy of your project source files. You will be making substantial changes and should have a backup.
- Open your source files in Windows Explorer and replace your files with the files in Authentication.zip. The App_Start folder can be completely replaced. (note: do not delete files from your project that are not in the zip file).
- Open your project in Visual Studio. Click the icon "Show All Files" at the top of Solution Explorer. Look through your project for files that are excluded (they will have gray icons), right-click on them and select "Include in Project."
- If your project name not "mis424Assignments" you need to replace all instances of "mis424Assignments" with the name of your project. Use VS's replace feature with settings "entire solution", and "case sensiitive".
- Delete the two folders "Providers" and "Results."
- web.config: Make sure the connection string "DefaultConnection" is not commented out.
- Decorate a controller with the [Authorize] filter as described in Assignment 2, exercise 2, steps b & c. Test. You should be prompted for authentication.
- 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 any other 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
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 query 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.