예제 #1
0
        public static void CreateRequisition(List <Cart> carts, long empId)
        {
            List <long> reqs = RequisitionDAO.GetAllRequisitions();
            Employee    emp  = new Employee();

            emp.EmpId = empId;
            Requisition req = new Requisition();
            long        arg = reqs.Count == 0 ? 0 : reqs.Max();

            req.ReqCode       = string.Format(String.Format("#R{0:0000000000}", arg + 1));
            req.DateOfRequest = DateTime.Now;
            req.Status        = "Pending Approval";
            req.Employee      = emp;
            long reqId = RequisitionDAO.SaveRequisition(req);

            req.ReqId = reqId;
            List <RequisitionDetails> reqDetailsList = new List <RequisitionDetails>();
            Inventory item = null;

            foreach (Cart c in carts)
            {
                item        = new Inventory();
                item.ItemId = c.Item.ItemId;
                RequisitionDetails reqDetail = new RequisitionDetails();
                reqDetail.Requisition = req;
                reqDetail.Item        = item;
                reqDetail.Quantity    = c.Quantity;
                reqDetail.Balance     = c.Quantity;
                reqDetailsList.Add(reqDetail);
            }
            RequisitionDetailsDAO.SaveRequisitionDetails(reqDetailsList);
            CartDAO.DeleteCarts(empId);
        }