public void PersistPO(List <PurchaseOrderUtil> newPOUlist, POBatch batch, LUUser user)
        {
            Dictionary <PurchaseOrder, List <PurchaseOrderItems> > poitemsList = new Dictionary <PurchaseOrder, List <PurchaseOrderItems> >();

            foreach (PurchaseOrderUtil npo in newPOUlist)
            {
                PurchaseOrder po = new PurchaseOrder();
                po.PuchaseOrderNo       = npo.PoNumber;
                po.OrderEmpID           = user.UserID;
                po.OrderDate            = npo.OrderDate;
                po.DeliveryAddress      = "Store Address";
                po.POStatus             = PurchaseOrderStatus.Requested.ToString();
                po.SupplierID           = npo.Supplier.SupplierID;
                po.DONumber             = "";
                po.PORemark             = npo.Remark;
                po.ExpectedDeliveryDate = Convert.ToDateTime(npo.ExpectedDeliveryDate);
                po.POBatchID            = batch.POBatchID;
                PODao.db.PurchaseOrders.Add(po);
                PODao.db.SaveChanges();

                poitemsList.Add(po, npo.Items);
            }

            PersistPoItems(poitemsList, user);
        }
        public void SavePurchaseOrder(List <PurchaseOrderUtil> newPOUlist, LUUser user)
        {
            PurchaseOrderItemDao poitem = new PurchaseOrderItemDao();

            try
            {
                POBatch batch = new POBatch();
                batch.POBatchDate = DateTime.Now;
                batch.Printed     = false;
                batch.GeneratedBy = user.UserID;
                POBatchDao.db.POBatches.Add(batch);
                POBatchDao.db.SaveChanges();

                PersistPO(newPOUlist, batch, user);
            }
            catch (DbEntityValidationException ea)
            {
                foreach (var eve in ea.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
        public bool CreatePO(POBatch poBactch, PurchaseOrder Order)
        {
            bool result           = false;
            LogicUniStoreModel db = new LogicUniStoreModel();

            db.POBatches.Add(poBactch);
            db.SaveChanges();
            Order.POBatchID = poBactch.POBatchID;
            db.PurchaseOrders.Add(Order);
            result = db.SaveChanges() > 0 ? true : false;
            return(result);
        }