Exercise 3: Querying and modifying orders¶
You can earn 5 points with the completion of this exercise.
In this exercise, we will implement CRUD (create, retrieve, update, delete) operations for Order
entities. This exercise is similar to the previous one; feel free to look back to the solutions of that exercise.
The properties of Model.Order
are:
ID
: theID
of the database serialized usingToString
Date
,Deadline
,Status
: taken from the database directlyPaymentMethod
: taken from theMethod
field of thePaymentMethod
complex entityTotal
: the cumulative sum of the product ofAmount
andPrice
for all items associated with this order (OrderItems
)
You will need to implement the management methods related to orders: ListOrders
, FindOrder
, InsertOrder
, DeleteOrder
, and UpdateOrder
.
Before starting the tasks below, do not forget to add and initialize an orderCollection
in the repository class similar to the other one.
Listing¶
-
Method
ListOrders
receives astring status
parameter. If this value is empty ornull
(see:string.IsNullOrEmpty
) list all orders. Otherwise, list orders where theStatus
field is identical to thestatus
received as a parameter. -
Method
FindOrder
returns the data of a single order identified bystring id
. If no record with the sameID
exists, this method shall returnnull
.
Creation¶
-
Implement the method
InsertOrder
. The following information is provided to create the new order:Order order
,Product product
, andint amount
. -
You need the set the following information in the database entity:
CustomerID
,SiteID
: find a chosenCustomer
in the database and copy the values from this record from fields_id
andmainSiteId
. Hard-wire these values in code.Date
,Deadline
,Status
: take these values from the value received asorder
parameterPaymentMethod
: create a new instance ofPaymentMethod
. TheMethod
should bePaymentMethod
from the object received through theorder
parameter. LeaveDeadline
asnull
.OrderItems
: create a single item here with the following data:ProductID
andPrice
: take the values from the parameterproduct
Amount
: copy value from the method parameteramount
Status
: equals to theStatus
field of parameterorder
- other fields (related to invoicing) should be left as
null
!
Delete¶
DeleteOrder
should delete the record specified by the ID
.
Modification¶
When updating the record in UpdateOrder
, only update the information present in Models.Order
: Date
, Deadline
, Status
, and PaymentMethod
. Ignore the value Total
; it does not need to be considered in this context.
You can combine multiple updates using Builders<Entities.Order>.Update.Combine
.
Keep in mind that the IsUpsert
property should be set to false
in the update!
The method should return true
if there were a record with a matching ID
.
Testing¶
You can test the functionalities using the Orders
link in the test web app. Verify the behavior of Filter
, Add new order
, Edit
, Details
, and Delete
too!
SUBMISSION
Create a screenshot of the web page listing the orders after successfully adding at least one new order. Save the screenshot as f3.png
and submit it with the other files of the solution. The screenshot shall display the list of orders. Verify that your Neptun code is visible on the image at the bottom of the page! The screenshot is required to earn the points.