NWEC P L002 Opt1
NWEC P L002 Opt1
NWEC P L002 Opt1
NET
Tr ain in g A ssign me nt s
Version 1.1
Hanoi, 06/2019
Lab Guides Web Development in .NET Issue/Revision: x/y
RECORD OF CHANGES
Prerequisites:
Problem Requirements:
This assignment challenges you to develop a comprehensive quiz application using ASP.NET Core and
Entity Framework Core (EF Core). You'll explore various functionalities like building a well-structured
application, implementing data access with EF Core, creating a RESTful API, and securing user interaction.
Description:
Based on the Entity Framework Core assignment, you will kickstart the development of a Quiz Application
using ASP.NET Core and Entity Framework Core.
Function Requirements:
• Setup Projects
o Ensure the project structure (NWEC.P.L001) meets requirements.
o Verify the connection string in appsettings.json and DbContext for correct configuration.
Hints:
• Organize the project structure into separate folders for DAL, BLL, and API.
• Utilize data annotations or Fluent API to enforce business rules and relationships in entity models.
• Write additional methods in services if necessary
Business Rules:
• Entity models should accurately represent the data structure for quizzes, questions, and answers.
• DbContext configuration should define relationships between entities (e.g., one-to-many, many-to-
many).
• Connection string should be stored securely in appsettings.json and accessed via IConfiguration in
Program.cs.
Evaluation Criteria:
• Successful creation of ASP.NET Core Web API project with appropriate project structure.
• Correct definition of entity models with required properties, constraints, and relationships.
Submission file:
Description:
This task focuses on implementing routing, controllers, HTTP methods, and model binding to build RESTful
endpoints for managing quizzes, questions, and answers within the Quiz Application.
Functions:
• Routing Configuration:
o Use attribute routing ([Route] attribute) to define custom routes for controller actions.
o Configure routing to map incoming HTTP requests to appropriate controller actions based on
route templates.
• Dependency Injection (DI):
o Configure dependency injection services (AddTransient, AddScoped, AddSingleton) in
Program.cs to inject dependencies into controllers, services, and middleware.
o Inject dependencies for use in controllers
• Controllers Implementation:
o Create controllers (UsersController, RolesController, QuizzesController,
QuestionsController) to handle CRUD operations for quizzes, questions, and answers.
o Implement action methods for HTTP GET, POST, PUT, DELETE operations corresponding
to API endpoints.
• Quiz Application API Reference:
Quiz API:
o GET /quizzes/{id}
▪ Description: Get details of a specific quiz by ID.
▪ Response:
- QuizViewModel: Title, Description, Duration, IsActive
o GET /quizzes
▪ Description: Retrieve a list of all quizzes.
▪ Response:
- List<QuizViewModel>
o POST /quizzes
▪ Description: Create a new quiz with questions.
▪ Action method: public async Task<IActionResult>
CreateQuizWithQuestions(QuizCreateViewModel quizCreateViewModel)
▪ Request Body:
- QuizCreateViewModel: Title, Description, Duration, IsActive,
QuestionIdWithOrders(ICollection<QuestionIdWithOrderViewModel>)
- QuestionIdWithOrderViewModel: QuestionId, Order
▪ Response: bool
o PUT /quizzes/{id}
User API:
o GET /users/{id}
▪ Description: Get details of a specific user by ID.
Role API:
o GET /roles/{id}
▪ Description: Get details of a specific role by ID.
▪ Response:
- RoleViewModel: Id, Name, Description, IsActive
o GET /roles
▪ Description: Retrieve a list of all roles.
▪ Response:
- List<RoleViewModel>
o POST /roles
▪ Description: Create a new role.
▪ Action method: public async Task<IActionResult>
CreateRole(RoleCreateViewModel roleCreateViewModel)
▪ Request Body:
- RoleCreateViewModel: Name, Description, IsActive.
▪ Response: bool
o PUT /roles/{id}
▪ Description: Update an existing role by ID.
Hints:
• Use attribute routing ([Route]) to define custom routes for controller actions.
• Implement controller actions to handle HTTP GET, POST, PUT, DELETE requests for different
resource endpoints.
• Utilize model binding to bind JSON data from requests to action method parameters.
Business Rules:
• Ensure controllers follow RESTful conventions with separate controllers for different resource types
(users, roles, quizzes, questions, answers).
• Use appropriate HTTP methods (GET, POST, PUT, DELETE) for performing CRUD operations on
resources.
• Implement model binding to handle request data and enforce data validation rules.
Evaluation Criteria:
• Successful implementation of controllers with action methods for CRUD operations on quizzes,
users, roles
• Proper routing configuration to map HTTP requests to controller actions based on route templates.
• Use of HTTP methods and model binding to process request data and interact with the DbContext
for data persistence.
• Adherence to RESTful principles and separation of concerns within controllers for different resource
types.
Submission file:
Description:
In this task, you will explore middleware, and error handling to enhance the robustness and scalability of the
Quiz Application.
Function Requirements:
• Middleware Configuration:
o Authentication Middleware:
IAuthService:
▪ Task<LoginResponseViewModel> LoginAsync(LoginViewModel
loginViewModel);
- LoginViewModel: UserName, Password.
- LoginResponseViewModel: UserInformation (JSON string), Token, Expires
▪ Task<LoginResponseViewModel> RegisterAsync(RegisterViewModel
registerViewModel);
- RegisterViewModel: FirstName, LastName, Email, UserName, PhoneNumber,
Password, ConfirmPassword, DateOfBirth.
- LoginResponseViewModel: UserInformation (JSON string), Token, Expires
AuthController:
▪ POST /login
▪ Description: Login with UserName and Password.
▪ Action method: public async Task<IActionResult> Login(LoginViewModel
loginViewModel)
▪ Request Body:
- LoginViewModel: UserName, Password.
▪ Response:
- LoginResponseViewModel: UserInformation (JSON string), Token, Expires
▪ POST /register
▪ Description: Register with UserName and Password.
▪ Action method: public async Task<IActionResult>
Register(RegisterViewModel registerViewModel)
▪ Request Body:
- RegisterViewModel: FirstName, LastName, Email, UserName,
PhoneNumber, Password, ConfirmPassword, DateOfBirth.
▪ Response:
- LoginResponseViewModel: UserInformation (JSON string), Token, Expires
Requirements:
Requirements:
▪ Configure CORS policies to specify which origins, methods, and headers are
allowed.
Origins: http://localhost:4200, https://localhost:4200
Hints:
Business Rules:
Evaluation Criteria:
Submission file:
Description:
This task focuses on implementing authentication/authorization mechanisms, enabling logging for application
events, and addressing security considerations within the Quiz Application.
Function Requirements:
• Logging Configuration:
o Integrate Serilog Frameworks
▪ Choose Serilog to handle logging in your ASP.NET Core application.
▪ Install the required NuGet packages (Serilog.AspNetCore,
Serilog.Extensions.Logging, etc.) and set up the logger in your application startup.
o Configure Logging Sinks
▪ Define logging sinks to specify where log messages should be written (e.g., file
system, database, console).
▪ Common sinks include:
▪ File Logging: Configure Serilog or NLog to write log messages to text files
on disk.
Hints:
• Use ASP.NET Core Identity for user authentication and role-based authorization.
• Configure JWT authentication for stateless, token-based authentication with custom token validation
logic.
• Integrate logging frameworks into the ASP.NET Core application to capture and store log messages.
Business Rules:
Evaluation Criteria:
• Implementation of authentication middleware to secure API endpoints using ASP.NET Core Identity
with JWT.
• Configuration of logging framework to capture application events and user actions.
• Adherence to security best practices to prevent security vulnerabilities (e.g., input validation,
HTTPS/TLS usage).
Submission file:
Description:
This task focuses on documenting RESTful APIs using Swagger/OpenAPI, implementing API versioning,
and exploring deployment strategies for ASP.NET Core applications.
Function Requirements:
• API Versioning:
o Implement API versioning to manage backward compatibility and support evolving API
designs.
o Choose a versioning strategy (e.g., URL-based versioning, header-based versioning) and
apply it to controllers and actions.
o Include version information in API responses and request headers for version negotiation.
• Deployment Strategies:
o Explore deployment options for ASP.NET Core applications (IIS Windows Server, Docker,
Azure App Service).
o Configure environment-specific settings (e.g., connection strings, API keys) for deployment.
o Discuss considerations for scalability, performance, and maintenance in different
deployment environments.
Hints:
• Use the Swashbuckle.AspNetCore NuGet package to integrate Swagger/OpenAPI into the ASP.NET
Core project.
• Apply versioning attributes (e.g., [ApiVersion], [ApiVersioning]) to controllers and actions for version
control.
Business Rules:
• API documentation should accurately describe endpoints, request parameters, and response
payloads using Swagger/OpenAPI annotations.
• API versioning should be implemented to manage changes and maintain backward compatibility for
consumers.
Evaluation Criteria:
• Successful integration of Swagger/OpenAPI for API documentation with interactive Swagger UI.
• Correct implementation of API versioning using chosen versioning strategy (e.g., URL-based,
header-based).
• Compliance with best practices for API documentation, versioning, and deployment strategies.
Mark Scale:
OOP design 10% Function requirements 60%
Business rules 15% Main function 15%