Skip to content

Commit

Permalink
Merge pull request #82 from bmeviauac01/hf2024eng
Browse files Browse the repository at this point in the history
Translated HF1 and HF2 to English
  • Loading branch information
tibitoth authored Aug 27, 2024
2 parents b918496 + 1fe7d69 commit 8f2ab59
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
31 changes: 28 additions & 3 deletions docs/en/homework/ef/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Exercise: Entity Framework

This exercise is optional. You may earn **2 points** by completing this exercise.
You may earn **2 points** by completing this exercise.

Use GitHub Classroom to get your git repository. You can find the **invitation link in Moodle**. Clone the repository created via the link. It contains a skeleton and the expected structure of your submission. After completing the exercises and verifying them, commit and push your submission.

Expand Down Expand Up @@ -68,10 +68,10 @@ There are unit tests available in the solution. The test codes are commented out

The image does not need to show the exact same source code that you submit; there can be some minor changes here and there. That is, if the tests run successfully and you create the screenshot, then later you make some **minor** change to the source, there is no need for you to update the screenshot.

## Exercise 2 optional: Repository implementation using Entity Framework (0 points)
## Exercise 2: Repository implementation using Entity Framework (2 points)

!!! note ""
In the evaluation, you will see the text “imsc” in the exercise title; this is meant for the Hungarian students. Please ignore that.
This exercise can be solved after completing the first exercise.

The Entity Framework DbContext created above has some drawbacks. For example, we need to trigger loading related entities using `Include` in every query, and the mapped entities are bound to precisely match the database schema. In complex applications, the DbContext is frequently wrapped in a repository that handles all peculiarities of the data access layer.

Expand All @@ -87,3 +87,28 @@ Implement the methods of class `ProductRepository.

!!! example "SUBMISSION"
Upload the changed C# source code.

## Exercise 3 optional: Logical Deletion with Entity Framework (0 points)

!!! note ""
In the evaluation, you will see the textimscin the exercise title; this is meant for the Hungarian students. Please ignore that.

Deleting data from a database is an operation that can have numerous unintended consequences. Restoring deleted data is much more difficult, and sometimes it is not even possible without repercussions. Deleting data can result in the loss of the entire data history, making it impossible to know the state before deletion or to use it in various statistics. Moreover, there are cases where relationships with other tables and foreign key constraints exist, and deletion affects those tables as well.

To overcome these problems, the most common solution is to implement a non-permanent deletion, known as a soft delete. In this case, a field (typically named `IsDeleted`) is used to indicate that the data has been deleted. Thus, the data remains in the database, but we can filter it to see whether it has been deleted.

A naive implementation of filtering is not convenient. Imagine having to add a condition to every query or save operation to ensure that deleted items are not affected. To address this, it is advisable to use one of Entity Framework's features, the *Global Query Filter*. This allows us to define filter conditions that are automatically applied to every query globally by Entity Framework.

Implement soft deletion for the previously created `DbProduct` class (there are multiple solutions; feel free to choose any of them):

!!! important "Modifiability"
Although the previous task had a restriction against overriding the `OnConfiguring` method, you are free to do so here if necessary (and you can also override other functions in the `DBContext` implementation)!

1. Add an `IsDeleted` variable that indicates to our application whether the entity is in a deleted state!

1. Add a *QueryFilter* that filters out the products that have already been deleted in every query, so they are not returned!

1. Modify the deletion behavior in the database **generally** by extending the `DbContext` save operations (EFCore provides several extension points for this) so that instead of performing a true deletion, it only changes the `IsDeleted` variable! Do not change the deletion operation in the repository for modification!

!!! example "SUBMISSION"
Upload the modified C# source code.
11 changes: 5 additions & 6 deletions docs/en/homework/index.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Optional homework
# Homework

These exercises are **optional**. You can earn **extra points** that are added to your exam score. Maximum 2 points per homework. In the exercises and the evaluation results, you will see a text “iMsc”; these iMsc points are not counted! (These are special points for Hungarian curriculum). All non-iMsc exercises are available for extra points on this course, 5 homeworks, maximum 2 points per homework, maximum 10 points. Here you find the exercise descriptions; the submission of the solutions is expected via GitHub Classroom. If you fail to submit the exercies exactly as in the guide, or it is late, you get no points at all! Make sure to follow the guide and do **everything in time**!
With these exercises you can earn **points** that are added to your exam score. Maximum 4 points per homework. In the exercises and the evaluation results, you will see a text “iMsc”; these iMsc points are not counted! (These are special points for Hungarian curriculum). All non-iMsc exercises are available for points on this course, 5 homeworks, maximum 4 points per homework, maximum 20 points. Here you find the exercise descriptions; the submission of the solutions is expected via GitHub Classroom. If you fail to submit the exercies exactly as in the guide, or it is late, you get no points at all! Make sure to follow the guide and do **everything in time**!

!!! important "Working code"
You are expected to write code that actually works! Your code will be executed, and it is required to fulfill the specified task.

## The exercises

1. [MSSQL server-side programming](mssql/index.md)
1. [ADO.NET data access](adonet/index.md)
1. [Entity Framework](ef/index.md)
1. [MongoDB](mongodb/index.md)
1. [REST API and Web API](rest/index.md)
Expand Down Expand Up @@ -46,10 +45,10 @@ Some of the exercises require you to create a screenshot. This screenshot is pro
- For writing C# code (most homework, except the first one):
- Microsoft Visual Studio 2022 [with the settings here](VisualStudio.md)
- When using Linux or macOS, you can use Visual Studio Code, the .NET SDK, and [dotnet CLI](https://docs.microsoft.com/en-us/dotnet/tools/).
- [.NET **6.0** SDK](https://dotnet.microsoft.com/download/dotnet/6.0)
- [.NET **8.0** SDK](https://dotnet.microsoft.com/download/dotnet/8.0)

!!! warning ".NET 6.0"
Mind the version! You need .NET SDK version **6.0** to solve these exercises.
!!! warning ".NET 8.0"
Mind the version! You need .NET SDK version **8.0** to solve these exercises.

On Windows, it might already be installed along with Visual Studio (see [here](VisualStudio.md#check-and-install-net-sdk) how to check it); if not, use the link above to install (the SDK and _not_ the runtime). You need to install it manually when using Linux or macOS.

Expand Down
21 changes: 19 additions & 2 deletions docs/en/homework/mssql/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Exercise: MSSQL server-side programming

This exercise is optional. You may earn **2 points** by completing this exercise.
You may earn **4 points** by completing this exercise.

Use GitHub Classroom to get your git repository. You can find the **invitation link in Moodle**. Clone the repository created via the link. It contains a skeleton and the expected structure of your submission. After completing the exercises and verifying them, commit and push your submission.

Expand Down Expand Up @@ -32,7 +32,24 @@ Make sure to verify the behavior of the trigger under various circumstances.

Create a screenshot that displays sample records in the `Customer` table with the automatically populated date values. Make sure that the database name and your Neptun code are visible on the screenshot. Save the screenshot as `f1.png` and upload it as part of your submission!

## Exercise 2 optional: Product recommended age (0 points)
## Exercise 2: Invoice Cancellation (2 points)

We would like to provide an option to cancel orders using a stored procedure. This procedure will invalidate an invoice identified by the customer's name and the order ID, then restore the inventory by iterating through the items associated with the order.

1. Create a stored procedure named cancel_invoice that accepts two parameters: the customer's name (named `name`) and the order ID (named `orderId`).

1. The stored procedure should verify whether an invoice exists with the given information. If not, it should throw an exception. The exception's `error_number` should be 51000.

1. If the data is valid, the stored procedure should retrieve all the products listed on the invoice, check the quantities ordered, and add those quantities back to the inventory. (HINT: You may need to gather data from multiple tables, or possibly use a cursor).

Test the procedure to ensure it works correctly!

!!! example "SUBMISSION"
Submit the trigger code in the `f2.sql` file. The SQL file should contain only a single statement (just one `create procedure cancel_invoice`), and should not include any `use` or `go` commands!

Create a screenshot showing the execution of the stored procedure and its effects, as well as what happens when incorrect data is provided (you can use a window with two tabs, for example). The screenshot should display the name of your database (your Neptun code). Save the screenshot as `f2.png` and submit it as part of your solution!

## Exercise 3 optional: Product recommended age (0 points)

!!! note ""
In the evaluation, you will see the text “imsc” in the exercise title; this is meant for the Hungarian students. Please ignore that.
Expand Down

0 comments on commit 8f2ab59

Please sign in to comment.