Allows User to Decide Least Wanted Situation in System

This will be the last week of me being a part of this group development team. So I will be completing my last few implementation, alongside with integration tests.

First and foremost, I will need to solve issue that I mention last week, where item.StockQuantity being negative. It is not wrong but it is least wanted situation to happen in real world. To handle this situation, we came up with an idea to force throw new DbUpdateException(). Hence, Implement try catch statement in ViewModel class to prompt a selection dialog using the error thrown (parameter = e.Message). In the dialog box, system users are given two options, "continue" or "cancel" on their consent that item.StockQuantity will be update as negative value if they would have pick "continue".

Next, I wrote few tests in service class and ViewModel integration tests. Service tests is mainly to test out if the transaction I about to implement would commit changes successfully and rollback if there is database update errors. While, ViewModel integration tests is to determine if dialog would be prompt upon error thrown and their behavior works correctly upon user selection.

Implementation is achieved by me using two variable to control the if else statement below:
///transaction///
///Codes that check if stockQuantityNegative is true or false///
if (stockQuantityNegative && rollback)
{
throw new DbUpdateException("Stock Quantity for item {id} will be negative.\nDo you want to continue?");
}

///rollback or commits transaction///
///end of transaction///

Initially Ready To Pick method in ViewModel would called as such _service.ReadyToPickVM(parameters, true). In service/repository class, method is ReadyToPickVM(Parameter parameters, bool rollback). As initial ReadyToPick function deemed rollback to be true, the system would check if stockQuantityNegative is true to meet requirement above. If the statement do meet, system will prompt error and rollback all changes. Dialog will prompt on UI, _service.ReadyToPickVM(parameters, false) will be triggered if user clicks “continue” and save item.StockQuantity as negative value; else the system will not do anything after rollback.

After implementation is done, I make sure the tests passes. I alter few logic and in implementation and tests, making sure it is good to go. I then push my latest code to repository and marks the end of my participant in this team.

Last but not least, special thanks to my supervisor Peter for allowing me being a part of this group development team!

Leave a Reply