Local Code Challenge
In this challenge, you'll update the Issue Tracker API's Issues endpoint to prevent under-posting.
You'll be completing this challenge using an IDE or code editor locally on your own computer. Download the code to get started and use the tools in your IDE or code editor to help you complete it. When you're ready, upload your finished code to run a series of tests and make sure everything's in working order!
Extra tips:
Tasks
Here are the tasks that you need to complete for this code challenge. If you get stuck completing any of these tasks, see below for a list of detailed tasks.
Set up the DTO...
- Add a folder to the root of the "IssueTracker" project named "Dto"
- Add a class to the "Dto" folder named
IssueDto
- Add properties to the
IssueDto
class using theIssue
model class as a guide- Be sure to use nullable types where appropriate
- Add
Required
data annotation attributes to the appropriate properties - Add a
MaxLength
data annotation attribute to theName
property in order to restrict the length of the value to 100 characters - Add a
MaxLength
data annotation attribute to theEmail
property in order to restrict the length of the value to 255 characters - Add a method named
ToModel
that converts the DTO to an instance of theIssue
model class
Update the IssueController...
- Update the
Post
action method to use the DTO - Update the
Put
action methodβ¦- Update the action method to use the DTO
- Update the return type to
IHttpActionResult
- Return a call to the
BadRequest
method if theModelState.IsValid
property is false - Return a call to the
StatusCode
method passing
Project Overview
As you complete the code challenges in this course, you'll be working on a simple API for creating, reading, updating, and deleting user issues. When completed, this API could be used as the back-end for a simple issue tracker client.
The provided Visual Studio solution includes an empty ASP.NET project, a shared class library project, and a test project. The shared class library project contains Entity Framework related classes (repository, database context, database initializer, and two model classes) to enable data persistence. The test project contains a collection of unit tests that will verify if your code implements all of the necessary requirements for each code challenge.
Note: When opening the Visual Studio solution for the first time, you'll be prompted with a security warning, for each project. Visual Studio does this to ensure that you're aware of the risks of executing code from untrusted sources. Go ahead and click the "OK" button to continue with opening the project.
Getting Started
Once you've downloaded the files for the code challenge, extract the ZIP file, and open into Visual Studio 2017 the IssueTracker.sln file located in the "src" folder.
Each code challenge will include instructions listing the specific tasks that you need to complete. To help determine when you've successfully completed all of the tasks, you can use Visual Studio's Test Explorer window to run all of the provided unit tests. If all of the tests pass, you're ready to upload your solution! If a one or more tests fail, review the error messages for hints on how you can resolve the issues.
Some of the challenges are purely setup or configuration related, so there won't necessarily be something that you easily manually test by debugging the application. For those challenges, you'll have to rely solely upon the provided unit tests to check if you've successfully completed all of the required tasks. Other challenges will have you adding a controller or adding/updating action methods. For those challenges, you can manually debug the application using a browser or a tool like Postman, in addition to running the provided unit tests.
As a convenience, the root of the "IssueTracker" ASP.NET project contains a gulp script that you can run using Visual Studio's Task Runner Explorer window. The gulp script contains a "default" task that will restore NuGet packages (if necessary), build the solution, run the unit tests, and if all of the tests pass, create a ZIP file of your solution. You'll find the "project.zip" file in the root folder (the folder that contains the README.md file). Upload this file when you're ready to complete the challenge.
Detailed Tasks
Set up the DTO...
- Add a folder to the root of the "IssueTracker" project named "Dto"
- Add a class to the "Dto" folder named
IssueDto
- Add properties to the
IssueDto
class using theIssue
model class as a guide- A property of type
int
namedId
- A property of type
DateTime?
namedReportedOn
- A property of type
string
namedName
- A property of type
string
namedEmail
- A property of type
int?
namedDepartmentId
- A property of type
string
namedDescriptionOfProblem
- A property of type
Issue.SeverityLevel?
namedSeverity
- A property of type
bool
namedReproducible
- A property of type
- Add
Required
data annotation attributes to the appropriate propertiesReportedOn
Name
Email
DepartmentId
DescriptionOfProblem
Severity
- Add a
MaxLength
data annotation attribute to theName
property in order to restrict the length of the value to 100 characters - Add a
MaxLength
data annotation attribute to theEmail
property in order to restrict the length of the value to 255 characters - Add a method named
ToModel
that converts the DTO to an instance of theIssue
model class
Update the IssueController...
Update the Post
action method to use the DTO...
- Update the
issue
parameter's type toIssueDto
- Call the DTO's
ToModel
method to get an instance of a model to pass to the repository'sAdd
method - Set the DTO's
Id
property with the model'sId
property value after calling the IssueRepository'sAdd
method- This is necessary to do in order to update the DTO with the ID value that was generated from the database before the DTO is returned to the client
Update the Put
action method...
- Update the return type to
IHttpActionResult
- Return a call to the
BadRequest
method if theModelState.IsValid
property is false - Return a call to the
StatusCode
method passing in theHttpStatusCode.NoContent
enum value - Update the
issue
parameter's type toIssueDto
- Call the DTO's
ToModel
method to get an instance of a model to pass to the IssuesRepository'sUpdate
method