public IActionResult ApproveRequest(int id)
        {
            if (!(HttpContext.Session.GetString("role") == EmployeeRole.DEPTHEAD || HttpContext.Session.GetString("role") == "ActingHead"))
            {
                return(RedirectToAction(HttpContext.Session.GetString("role"), "Home"));
            }
            // push this to service
            Request request = requestService.FindRequestbyId(id);
            List <RequestDetails> rdList = requestDetailService.FindRequestDetailByRequestId(id);
            bool canBeFufilled           = true;

            //check if all items can be fufilled
            foreach (RequestDetails rd in rdList)
            {
                InventoryItem item = inventoryItemService.GetItemById(rd.InventoryItemId);
                if (item.RequestQty + rd.QtyRequested > item.QtyInStock)
                {
                    canBeFufilled = false;
                }
            }
            // if can be fufilled (qty is add to requestqty and status is changed to approved)
            if (canBeFufilled == true)
            {
                request.Status = Status.Approved;
                foreach (RequestDetails rd in rdList)
                {
                    InventoryItem item = inventoryItemService.GetItemById(rd.InventoryItemId);
                    item.RequestQty = item.RequestQty + rd.QtyRequested;
                    //send email notification if lowstock
                    if (item.QtyInStock - item.RequestQty < item.ReorderLevel)
                    {
                        emailService.sendlowstockemailnotifitcation(item.Id);
                    }
                }
            }
            else
            {
                request.Status = Status.PendingStock;
            }

            dbcontext.SaveChanges();

            return(RedirectToAction("Requestpendingapproval"));
        }
        public string ApproveRequest(int id)
        {
            // push this to service
            Request request = requestService.FindRequestbyId(id);
            List <RequestDetails> RDlist = requestDetailservice.FindRequestDetailByRequestId(id);
            bool canbefufilled           = true;

            //check if all items can be fufilled
            foreach (RequestDetails rd in RDlist)
            {
                InventoryItem item = inventService.GetItemById(rd.InventoryItemId);
                if (item.RequestQty + rd.QtyRequested > item.QtyInStock)
                {
                    canbefufilled = false;
                }
            }
            // if can be fufilled (qty is add to requestqty and status is changed to approved)
            if (canbefufilled == true)
            {
                request.Status = Enums.Status.Approved;
                requestService.updateStatus(request, Enums.Status.Approved);
                emailservice.sendrequestapprovalemailnotifitcation(request.EmployeeId);
                foreach (RequestDetails rd in RDlist)
                {
                    InventoryItem item = inventService.GetItemById(rd.InventoryItemId);
                    item.RequestQty = item.RequestQty + rd.QtyRequested;
                    //send email notification if lowstock
                    if (item.QtyInStock - item.RequestQty < item.ReorderLevel)
                    {
                        emailservice.sendlowstockemailnotifitcation(item.Id);
                    }
                }
            }
            else
            {
                request.Status = Enums.Status.PendingStock;
                requestService.updateStatus(request, Enums.Status.PendingStock);
                emailservice.sendrequestapprovalemailnotifitcation(request.EmployeeId);
            }

            return(JsonSerializer.Serialize(new { Id = id, Status = request.Status }));
        }