DPS907 WSA500 Assignment 2 – Fall 2017

Web service with associated entities. Implement add-new, edit-existing, and delete-item use cases.

Read/skim all of this document before you begin work.


Due date

Monday, September 18, 2017, at 11:00pm ET

Grade value: 5% of your final course grade

If you wish to submit the assignment before the due date and time, you can do that.



Create a web service that works with associated entities. Implement a typical range of use cases.


Introduction to the problem to be solved

We need a web service that will deliver data about the music business. The web service will support a typical range of use cases, including working with associated data.


Specifications overview and work plan

Here’s a brief list of specifications that you must implement:

  • Follows best practices
  • Implements the recommended system design guidance
  • Customized appearance on the landing web page
  • Uses Entity Framework and Code First technology
  • Supports HTTP GET, for get all and get one use cases, for the Artist entity
  • Supports HTTP GET, for get one, for the Artist entity, with associated Album data
  • Supports HTTP GET, for get one, for the Album entity, with associated Artist data
  • Supports HTTP POST, for the add new use case, for the Artist and Album entities
  • Supports HTTP PUT, for the edit existing use case, for the Album entity
  • Supports HTTP DELETE, for the delete item use case, for the Album entity
  • Includes a Fiddler log file that shows complete coverage of tests


During the class/session, your professor will help you get started and make progress on this assignment.

Every week, in the computer-lab class/session, your teacher will record a grade when you complete a specific small portion of the assignment. We call this “in-class grading“.

The in-class grading will be announced in-class by your professor.


Review the concepts if you need to

Whether you have been away from ASP.NET MVC web app programming for one or two academic terms, you should review some notes, to ensure that you use best practices and efficient design and coding techniques.

Our course notes have coverage, and more can be found in the professor’s recent web apps course notes.


Create resource (view) model classes easily and confidently

Remember, the purpose of a resource (view) model class is to package data for a use case. Always think about the use case, and what the end user (requestor) needs to send or receive.

We map an object (or collection) that’s based on a resource model class, to-and-from an object (or collection) that’s based on a design model class. We never accept or deliver design model objects to-and-from a requestor. We always transform the objects. That’s why we use AutoMapper.

So… how can you create resource model classes, easily and confidently? Your professor uses this thought process:

  1. Create a source code file to hold an entity’s resource models (e.g. Artist_vm.cs)
  2. Write the “add” class first (e.g. ArtistAdd)
  3. Copy the properties from the entity’s design model class, into this new class
  4. Remove the identifier property, and other properties that don’t make sense in an “add new” use case
  5. Edit the code if necessary, to remove or add attributes/annotations
  6. Next, write the “base” class, which will inherit from the “add” class; add the identifier property


General rule (reminder) about including associated data

When you include associated data in a response, make sure that the associated data does NOT include a reference back to the “parent” object.

In general, the <entity>Base resource model class does NOT include an associated object or collection. Therefore, if a “parent” class (e.g. ProductWithSupplier, or SupplierWithProducts) includes an object or collection, make sure that the data type of the associated object or collection is an <entity>Base type.


Getting started

Create a new web service, named Assignment2. It must use the “Web service project v1” project template.

Build/compile, and run (without debugging), to ensure that the app’s home > index view loads in a browser.


Doing the work

After configuring and studying the app’s structure, you can circle back and do the programming work.

As a reminder, your professor believes that the best way to work through any assignment is to do it incrementally. Get one thing working correctly, before moving on to the next. Test each part.

Therefore, you will probably be cycling through the following programming tasks, for each use case.

  1. Write the resource model class(es) that support the use case
  2. Add one or more AutoMapper mappings for the class(es) that you just added
  3. Write the Manager class method that performs the data service operation
  4. Create a controller, if necessary
  5. Write the controller method that implements the use case
  6. Test, using Fiddler, debug and fix if necessary

Incrementally doing these tasks will ensure that you’re making progress. You will also notice that they’re repetitive. That’s good, because the process will become familiar and natural to you.

Here are the use cases, from above:

  • Get all and get one use cases, for the Artist entity
  • Get one, for the Artist entity, with associated Album data included
  • Get one, for the Album entity, with associated Artist data included
  • Add new use case, for the Artist and Album entities
  • Edit existing use case, for the Album entity
  • Delete item use case, for the Album entity

Make sure that you study the code examples, from this course and from the web apps course, to learn and implement the best practice way of designing and coding each programming task listed above.


Info about the edit existing use case, for the Album entity

The Album entity class has four (4) properties. What can we edit? Only the Title property. It does not make sense to allow editing of any other property. (Think about it. If you cannot think of the reasons, ask your professor.)

Therefore, a resource model class that enables the edit existing use case for the Album entity will probably have only two (2) properties, the identifier, and the Title property.


Info about the delete item use case, for the Album entity

By default, we cannot delete an Album, if the Album has associated Track objects. Why? Cascade delete is turned off. Look at the data context class to confirm this.

Therefore, when you are testing, how can you test the delete item use case for the Album entity?

First, add a new Album object. At that point in its lifetime, it will not yet have any associated Track objects. As a result, you can delete it.


Testing your work

Use Fiddler.

Ensure that it has been configured to save the message bodies in requests and responses. (A default installation does not do this.) If you are using a College computer, this should have been configured, but check anyway. If you installed Fiddler on your own computer, follow the instructions on this document.

Test all scenarios (use cases).

When testing the “add new” scenario, remember:

  • The HTTP method is POST
  • The target is the collection URI
  • The request needs a Content-Type header
  • The message body needs a JSON object that matches the resource model
  • If you’re sending a DateTime property, send an ISO 8601 string. For example, “2016-09-14T23:00:00”.


Saving – “exporting” – your tests

On the left side list of requests, you can delete items that you do not want included in the export.

When you’re ready to save, choose File > Export Sessions > All Sessions…

The export format will be “HTTPArchive v1.2”. Click the Next button to choose a save location (your project’s root, in the same folder level as the “packages” folder and specify a filename. Name the file by using the project name (e.g. “<whatever>.har”).

(You can test whether the export was successful. How? First, close then re-open Fiddler. Choose File > Import Sessions. Select “HTTPArchive” as the import format. Navigate to the folder that holds the “har” file, and select it. Finally, browse through the request-response sessions.)


Reminder about academic honesty

You must comply with the College’s academic honesty policy.

Although you may interact and collaborate with others, you must submit your own work.


Submitting your work

Here’s how to submit your work, before the due date and time:

1. Locate the folder that holds your project files. (It has about three items, a Visual Studio “solution” file, a folder that has your project’s source code, and a “packages” folder.)

2. Make a copy of the folder. You will be uploading a zipped version of the copy.

3. Remove the “packages” folder from the copied folder; also, remove the “bin” and “obj” folders, which are in the project’s source code folder hierarchy.

4. Compress/zip the copied folder. The zip file SHOULD be about 1MB to 2MB in size. If it isn’t, you haven’t followed the instructions properly.

5. Login to My.Seneca/Blackboard. Open the Web Services course area. Click the “Assignments” link on the left-side navigator. Follow the link for this assignment. Submit/upload your zip file. The page will accept three submissions, so if you upload, then decide to fix something and upload again, you can do so.



























%d bloggers like this: