public List <RetrievalListDetailItem> DisplayRetrievalListDetail(int requisitionId) { List <RetrievalListDetailItem> retrievalListDetailItemDisplayList = new List <RetrievalListDetailItem>(); //get retrievalStatus by requisitionId string retrievalStatus = EFBroker_Disbursement.GetRetrievalStatusByRequisitionId(requisitionId); // dictionary with itemcode + totalrequestedQty Dictionary <string, int> itemcodeAndTotalRequestedQtyDictionary = new Dictionary <string, int>(); HashSet <String> uniqueItemcodeHashSet = new HashSet <string>(); List <Disbursement> disbursementList = EFBroker_Disbursement.GetDisbursmentListbyRetrievalID(requisitionId); // remove repeated itemcode in disbursementList foreach (Disbursement d in disbursementList) { foreach (Disbursement_Item dI in d.Disbursement_Item) { uniqueItemcodeHashSet.Add(dI.ItemCode); } } // accumulate totalRequestedQty if there is same itemCode in Disbursement, then foreach (string i in uniqueItemcodeHashSet) { string itemCode = i; int totalRequestedQty = 0; foreach (Disbursement d in disbursementList) { foreach (Disbursement_Item dI in d.Disbursement_Item) { if (dI.ItemCode == itemCode) { totalRequestedQty += (int)dI.TotalRequestedQty; } } } itemcodeAndTotalRequestedQtyDictionary.Add(itemCode, totalRequestedQty); } //create RetrievalListDetailItem to display in DisplayRetrievalListDetail base on retrievalStatus foreach (KeyValuePair <string, int> kvp in itemcodeAndTotalRequestedQtyDictionary) { int retrievedQty = 0; if (retrievalStatus == "Pending") { //default retrievedQty is same as totalRequestedQty retrievedQty = kvp.Value; } if (retrievalStatus == "InProgress") { //retrievedQty is same as value which inputted in warehouse retrievedQty = EFBroker_Disbursement.GetRetrievedQtyByRequisitionIdNItemCode(requisitionId, kvp.Key); } Item item = EFBroker_Item.GetItembyItemCode(kvp.Key); string bin = item.Bin; string description = item.Description; RetrievalListDetailItem retDetail = new RetrievalListDetailItem(bin, description, kvp.Value, kvp.Key, retrievedQty); retrievalListDetailItemDisplayList.Add(retDetail); } return(retrievalListDetailItemDisplayList); }