public ActionResult EmployeeRequisition([Bind] Requisition requisition)
        {
            Employee currentEmployee = (Employee)Session["User"];

            try
            {
                if (ModelState.IsValid)
                {
                    var q = (from x in requisition.RequisitionDetails
                             orderby x.ItemNo
                             select x).ToList();

                    for (int i = 0; i < q.Count() - 1; i++)
                    {
                        if (q[i].ItemNo == q[i + 1].ItemNo)
                        {
                            throw new RequisitionAndPOCreationException("Please ensure the items are not duplicated.");
                        }
                    }
                    if (requisition.RequisitionDetails == null || requisition.RequisitionDetails.Count == 0)
                    {
                        throw new RequisitionAndPOCreationException("Please ensure there are items added in the requisition.");
                    }

                    foreach (var item in requisition.RequisitionDetails)
                    {
                        if (item.Quantity == null || item.Quantity <= 0)
                        {
                            throw new RequisitionAndPOCreationException("Please ensure the item quantity is greater than zero.");
                        }
                        item.OutstandingQuantity = item.Quantity;
                    }

                    reqService.CreateRequisition(requisition, currentEmployee.EmployeeId);
                    pushSvc.NotificationForHeadOnCreate(currentEmployee.EmployeeId.ToString());

                    try
                    {
                        string   emailBody      = requisition.Employee.Department.Head.EmployeeName + ", You have a pending requisition from " + requisition.Employee.EmployeeName + ". Please go to http://" + uSvc.GetBaseUrl() + "/Head/EmployeeRequisition/" + requisition.RequisitionId + " to approve the request.";
                        Delegate delegateRecord = deptService.getDelegatedEmployee(requisition.DepartmentId);
                        if (delegateRecord != null) //if there is a delegate for the department, email will be addressed to the delegate and CC to the head.
                        {
                            emailBody = delegateRecord.Employee.EmployeeName + ", You have a pending requisition from " + requisition.Employee.EmployeeName + ". Please go to http://" + uSvc.GetBaseUrl() + "/Head/EmployeeRequisition/" + requisition.RequisitionId + " to approve the request.";
                            uSvc.SendEmail(new List <string>(new string[] { delegateRecord.Employee.Email }), "New Requisition Pending Approval", emailBody, new List <string>(new string[] { requisition.Employee.Department.Head.Email }));
                        }
                        else
                        {
                            uSvc.SendEmail(new List <string>(new string[] { requisition.Employee.Department.Head.Email }), "New Requisition Pending Approval", emailBody);
                        }
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(e.ToString());
                    }
                    return(RedirectToAction("DepartmentRequisitions"));
                }
            }
            catch (RequisitionAndPOCreationException e)
            {
                ViewBag.Error = e.Message.ToString();
            }

            ViewBag.ItemNo = new SelectList(invService.GetAllInventory(), "ItemNo", "Description");
            return(View(requisition));
        }