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

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

            voucherNo = "";


            //handle post action
            List <TempVoucherDetails> tempVoucherDetailsList = b.GetTempVoucherDetailsList(userID);

            if (createNewVoucherItemModalName == 1)
            {
                if (quantity == 0)
                {
                    TempData["QuantityError"] = "Please select a quantity to add to voucher. Quantity cannot be 0.";
                    return(RedirectToAction("Index"));
                }
                else
                {
                    b.CreateNewVoucherItem(userID, itemNumber, quantity, remark);
                    return(RedirectToAction(nameof(Index)));
                }
            }
            else if (voucherItemModalName == 1)
            {
                b.UpdateVoucherItem(rowID, quantity, remark, tempVoucherDetailsList);
            }

            if (itemSubmitted.Length != 0)
            {
                voucherNo = b.IDGenerator("V");
                foreach (var item in tempVoucherDetailsList)
                {
                    if (Array.Exists(itemSubmitted, i => i == item.RowID.ToString()))
                    {
                        b.AddItemsToVoucher(item.RowID, voucherNo, tempVoucherDetailsList);
                    }
                }
                b.CreateAdjustmentRecord(userID, voucherNo, "Pending Approval");

                //send notification email to Head of stationery department

                var boss = (from x in _context.User
                            join y in _context.Department
                            on x.UserId equals y.RepId
                            where y.DepartmentCode == "STAS"
                            select new
                {
                    email = x.EmailAddress,
                    name = x.Name
                }).First();

                string email = boss.email;
                await _emailSender.SendEmailAsync(email, "New Adjustment Voucher Pending Approval", "Dear " + boss.name + ",<br>There is a new adjustment voucher that needs your approval.<br><br>-- (Automated email, no reply required) --");

                return(Json(new { redirecturl = "AdjustmentRecords/Details/" + voucherNo }));
            }
            else if (itemSavedToDraft.Length != 0)
            {
                voucherNo = b.IDGenerator("V");
                foreach (var item in tempVoucherDetailsList)
                {
                    if (Array.Exists(itemSavedToDraft, i => i == item.RowID.ToString()))
                    {
                        b.AddItemsToVoucher(item.RowID, voucherNo, tempVoucherDetailsList);
                    }
                }
                b.CreateAdjustmentRecord(userID, voucherNo, "Draft");
                //return RedirectToAction(nameof(Index));
                return(Json(new { redirecturl = "AdjustmentRecords/Details/" + voucherNo }));
            }

            List <TempVoucherDetails> result = b.GetTempVoucherDetailsList(userID);

            //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));
        }