public async Task <IActionResult> Index(string itemNumber, int quantity, int rowID, string supplierCode, int createNewPOItemModalName, int POItemModalName, string[] itemSubmitted, string[] itemSavedToDraft)
        {
            ADTeam5User user = await _userManager.GetUserAsync(HttpContext.User);

            List <string> identity = userCheck.checkUserIdentityAsync(user);
            int           userID   = user.WorkID;

            poNo = "";

            //handle post action
            List <TempPurchaseOrderDetails> tempPurchaseOrderDetailsList = b.GetTempPurchaseOrderDetailsList();

            if (createNewPOItemModalName == 1)
            {
                if (supplierCode == null || supplierCode == "")
                {
                    TempData["SupplierNameError"]      = "Purchase order was not successfully raised. Please try again.";
                    TempData["SupplierSelectionError"] = "Please select supplier.";
                    return(RedirectToAction("Index"));
                }
                else
                {
                    b.CreateNewPOItem(userID, itemNumber, quantity, supplierCode);
                    return(RedirectToAction(nameof(Index)));
                }
            }
            else if (POItemModalName == 1)
            {
                if (supplierCode == null || supplierCode == "")
                {
                    TempData["SupplierNameError"]      = "Purchase order was not successfully raised. Please try again.";
                    TempData["SupplierSelectionError"] = "Please select supplier.";
                    return(RedirectToAction("Index"));
                }
                else
                {
                    b.UpdatePOItem(userID, rowID, quantity, supplierCode, tempPurchaseOrderDetailsList);
                }
            }

            if (itemSubmitted.Length != 0)
            {
                //split supplier
                var supplier = tempPurchaseOrderDetailsList.GroupBy(x => x.SupplierCode).Select(y => y.Key);
                foreach (var s in supplier)
                {
                    poNo = b.IDGenerator("PO");
                    foreach (var item in tempPurchaseOrderDetailsList)
                    {
                        if (Array.Exists(itemSubmitted, i => i == item.RowID.ToString()) && item.SupplierCode == s)
                        {
                            b.AddItemsToPO(item.RowID, poNo, tempPurchaseOrderDetailsList);
                            b.CreatePurchaseOrderRecord(userID, poNo, s, "Pending Delivery");
                        }
                    }
                }

                //return through ajax
                return(Json(new { redirecturl = "PurchaseOrderRecords" }));
            }
            else if (itemSavedToDraft.Length != 0)
            {
                var supplier = tempPurchaseOrderDetailsList.GroupBy(x => x.SupplierCode).Select(y => y.Key);
                foreach (var s in supplier)
                {
                    poNo = b.IDGenerator("PO");
                    foreach (var item in tempPurchaseOrderDetailsList)
                    {
                        if (Array.Exists(itemSavedToDraft, i => i == item.RowID.ToString()))
                        {
                            b.AddItemsToPO(item.RowID, poNo, tempPurchaseOrderDetailsList);
                            b.CreatePurchaseOrderRecord(userID, poNo, s, "Draft");
                        }
                    }
                }
                //return RedirectToAction(nameof(Index));
                return(Json(new { redirecturl = "PurchaseOrderRecords" }));
            }

            List <TempPurchaseOrderDetails> result = b.GetTempPurchaseOrderDetailsList();

            //calculate order total amount by supplier


            //Viewbag for category dropdown list, need to post back
            List <Catalogue> categoryList = new List <Catalogue>();
            var q = _context.Catalogue.GroupBy(x => new { x.Category }).Select(x => x.FirstOrDefault());

            foreach (var item in q)
            {
                categoryList.Add(item);
            }
            categoryList.Insert(0, new Catalogue {
                ItemNumber = "0", Category = "---Select Category---"
            });
            ViewBag.ListofCategory = categoryList;
            return(View(result));
        }