DPS907 WSA500 Assignment 4 – Fall 2017

Work with non-text media items.

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


Due date

Monday, October 2, 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.



Enable a simple web service to work with internet media types.


Introduction to the problem to be solved

We need a simple app, to keep track of musical instruments. Assume that this app is needed by a company that sells musical instruments.

For this assignment, there is a single entity, and it is not associated with another entity. The entity has properties to store a media item, which is a photo of the musical instrument.


Specifications overview and work plan

The following specifications apply to all of your assignments:

  • Follows best practices
  • Implements the recommended system design guidance
  • Customized appearance on the landing web page
  • Uses Entity Framework and Code First technology
  • Includes a Fiddler log file that shows complete coverage of tests

For this assignment, here is what we’re looking for:

  • Accept (upload) and deliver internet media types (a photo, and audio for DPS907 students)
  • Implement content negotiation


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.

DPS907 students must configure the app to handle a sound clip media item, in addition to a photo media item. 


Getting started

For this assignment, you will NOT be using the Chinook sample database. Therefore, you will NOT use the “Web service project v1” project template.

Instead, create a new web service, named Assignment4, with these features:

  • ASP.NET Web Application
  • No, do not add Application Insights to the project
  • The template will be “Web API”
  • Authentication will be “Individual User Accounts”
  • No, do not host in the cloud
  • No, do not add unit tests


Build/compile, and run (without debugging), to ensure that the app’s home > index view loads in a browser. Then, customize the view (with your name and some brief assignment info) before continuing.

This project will include the components needed to use a database, and Entity Framework Code First technology:

  • Its data context class is ApplicationDbContext, in the IdentityModels.cs source code file
  • You must add your own DbSet<TEntity> properties to this class

Update the project’s packages: In the NuGet package manager console, run the command “update-package”.


Add AutoMapper

Using the NuGet Package Manager, install AutoMapper.


Add the source code files that define the app’s structure

Add the source code files that define the app’s structure. As suggested above, build/compile after you add new items and perform edits.

In the Controllers folder, add a source code file to hold your data operations management methods, named Manager.cs. If you wish, you can copy that from another recent project (and edit the namespace name etc.).

Like you did in Assignment 1, and as you saw in Assignments 2 and 3, configure the Manager class with the necessary bits and pieces:

  • Reference to the data context
  • Fields for AutoMapper
  • Constructor code to configure AutoMapper

In the Models folder, add a source code file to hold your design model classes, named DesignModelClasses.cs.

In a new folder, probably named ServiceLayer, add a source code file to hold the media type formatter ByteFormatter.cs. If you wish, you can copy that from the course code example repository on GitHub or one of the Week 4 code examples. You have permission to use that source code file as-is. Make sure that you add it to the request-processing pipeline.

In the Controllers folder, add a source code file to hold your resource model (i.e. view model) classes. Its name will be Instrument_vm.cs.

In the Controllers folder, add a controller. Its type will be “Web API 2 Controller with read/write actions”. Its name will be InstrumentsController.cs.

At this point, do another build/compile, to ensure that your work was done correctly.


Add a design model class

DesignModelClassesThis app needs only one entity class, probably named “Instrument”. Here’s some info about the purpose of the properties in your professor’s example solution:

Category – The musical instrument category. For example “Acoustic guitar”, or “Electric guitar”.

ManufacturerName – As it suggests, the manufacturer’s name. For example, “Gibson”.

InstrumentName – As it suggests, the full product name of the instrument. For example, “Leon Aubert Violin Outfit Model 50”.

ModelCode – The model code number, or part number. Alphanumeric.

MSRP – The manufacturer’s suggested retail price. Integer.

PhotoContentType – The internet media type of the photo.

PhotoMedia – The data bytes of the photo.

DPS907 students must also add:

SoundClipContentType – The internet media type of the sound clip. 

SoundClipMedia – The data bytes of the sound clip. 


Remember to always use data annotations. And, remember to add a DbSet<TEntity> property for this new design model class, to the data context class.


Doing the work

After configuring 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. (You first saw this list in the Assignment 2 specifications.)

  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, as suggested from the simple sentence above:

  • Get all use case
  • Get one use case, which will also fetch the media item(s) bytes
  • Add new use case
  • Delete item use case
  • Change state, a command, to set/configure a musical instrument’s photo
  • (DPS907 students…) Change state, a command, to set/configure a musical instrument’s sound clip

As noted above, DPS907 students must configure the app to handle a sound clip media item, in addition to a photo media item. It is not a difficult task, but it will require careful thought and planning.

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. Also, use the comments and feedback that appears on your previous assignment checklists.


Info about the get all use case

You have probably (hopefully) observed that the common practice for returning a collection of objects that have media items, in most situations, is to NOT deliver the media items.

However, you can deliver information (metadata) about the media item. For example, in the code example, you saw that the media item size and content type were delivered. This data provides useful information to the requestor.


Info about the get one use case

As above, you have probably (hopefully) observed that you can deliver – from the manager object to the controller object – the media items when a single “instrument” object is requested. This gives the controller an opportunity to deliver – or not – the media item to the requestor.

This get one use case will use content negotiation in the controller object. Make sure to implement the best practice and convention for handling/delivering objects that include, or do not include, media items.


Info about the add new use case

This should be uncomplicated and straightforward to implement.

Add 8 to 12 instrument objects to your data store. Use realistic data. Do NOT enter crappy data. Visit an online store, or your own experience, to create data for musical instruments.


Info about the delete item use case

Implementing this item will help you manage the size of your data store, and give you an opportunity to delete items that you don’t want any longer for whatever reason (bad data, duplicated info, etc.).


Info about the change state (photo) use case

This will enable a requestor to add (or replace) a photo for a specific “instrument” object.

Implement this by using the command pattern.

Add photos for 5 to 10 instruments. Use realistic photos. Do not use the same photo for all instruments. If you need to, use a photo editor to crop or resize large photos.

Limit the size of the photo which can be uploaded, to about 200KB. The best place to decide that is in the controller method. Return the most correct response code and error message to the requestor. Use RFC 7231 to help determine the most correct response code.


(DPS907 students…) Info about the change state (audio) use case

This will enable a requestor to add (or replace) a sound clip for a specific “instrument” object.

Implement this by using the command pattern.

Add sound clips for 5 to 10 instruments. Use realistic sound clips. Do not use the same sound clips for all instruments. If you need to, use an audio editor to resample, trim, or make excerpts from large sound clips.

Limit the size of the sound clip which can be uploaded, to about 200KB. The best place to decide that is in the controller method. Return the most correct response code and error message to the requestor. Use RFC 7231 to help determine the most correct response code.

Where can you get sound clips?

  1. Create them yourself
  2. Download sample sounds

On My.Seneca/Blackboard, in the “Assignments” area of the course web site, there is an item named “Assignment 4 assets”. In that, there is a zip file that has three sample sounds.

Alternatively, you can search for sample sounds on the web. If you do this, respect the copyright and the wishes of the sound’s creator. Use public-domain or open-source audio if possible.


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). Make sure that you test error or error-like scenarios.


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

At this point in time, you should be familiar with the process:

  1. Copy your project
  2. Remove its packages, bin, and obj folders
  3. Zip and upload to the designated location on My.Seneca/Blackboard before the due date-and-time

If you need more details, look at the info in assignments 1 through 3.




































%d bloggers like this: