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: theIDof the database serialized usingToStringDate,Deadline,Status: taken from the database directlyPaymentMethod: taken from theMethodfield of thePaymentMethodcomplex entityTotal: the cumulative sum of the product ofAmountandPricefor 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
ListOrdersreceives astring statusparameter. If this value is empty ornull(see:string.IsNullOrEmpty) list all orders. Otherwise, list orders where theStatusfield is identical to thestatusreceived as a parameter. -
Method
FindOrderreturns the data of a single order identified bystring id. If no record with the sameIDexists, 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 chosenCustomerin the database and copy the values from this record from fields_idandmainSiteId. Hard-wire these values in code.Date,Deadline,Status: take these values from the value received asorderparameterPaymentMethod: create a new instance ofPaymentMethod. TheMethodshould bePaymentMethodfrom the object received through theorderparameter. LeaveDeadlineasnull.OrderItems: create a single item here with the following data:ProductIDandPrice: take the values from the parameterproductAmount: copy value from the method parameteramountStatus: equals to theStatusfield 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.