DPS907 notes – Tue Nov 5

More programming assignment discussion.

.

Programming assignment – the first due date is this Friday, November 8

The first due date for assignment work is on Friday, November 8. (We had previously discussed an earlier date, but that won’t be possible.)

Here’s a link to the work-in-progress assignment specifications. There’s enough there to enable you to get started, but the content will be edited and finalized by the beginning of today’s class/session.

Programming assignment

.

Topic coverage today

We’ll discuss the programming assignment.

And enumerations in our app domain data model.

Techniques…

When building and testing the app domain data model, use DropCreateDatabaseAlways<T> in the store initializer.

Use a ‘console’ project to help you test your work.

Creating initial data (for the WSA500 assignment) that includes geolocation data; Bing maps; elevation/altitude.

.

Enum types in the app domain data model

This section explains how to use an enum type in your app domain data model.

Create a new source code file; in the code example, it’s named “OtherClassesAndEnums.cs”.

Change its namespace to <projectName>.OtherClassesAndEnums.

Replace the existing class with your own enum(s).

In the app domain class file, add a using directive for the namespace (above) that holds the enums.

Add a property to hold the enum type.

In the code example, the store initializer code was changed to set the property’s value.

View model

In the view model, the property name matches the name used in the app domain model class. Its type is string. The media formatter handles the conversion to-and-from the underlying integer type.

Handle and validate incoming data (typically POST and PUT) for the enum

When a user sends data with the request (typically POST and PUT), how do you handle and validate incoming data for the enum?

Add code to the repository method. (The controller’s ModelState.IsValid check will ensure that the incoming data is a string, but it won’t check the validity of the data.)

In summary, use the Enum.TryParse() method to validate the incoming data. If TryParse() returns false, then immediately return null from the repository method, so that the controller will return the appropriate HTTP status code (typically 415) to the requestor.

.

.

.

.

.

.

.

.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: