public EFModel.PurchaseOrder Map(PurchaseOrder p)
        {
            EFModel.PurchaseOrder po = new EFModel.PurchaseOrder();
            po.QRCodeId = p.QRCodeId;
            po.QRCodeShortURL = p.QRCodeShortURL;
            po.PurchaseOrderNumber = p.PurchaseOrderNumber;
            po.GroupQRCode = p.GroupQRCode;
            po.ProfileId = (p.Profile == null ? null : (int?)p.Profile.Id);
            po.GroupId = (p.Group == null ? null : (int?)p.Group.Id);
            po.VendorId = (p.Vendor == null ? null : (int?)p.Vendor.Id);

            return po;
        }
        public PurchaseOrder Map(EFModel.PurchaseOrder p)
        {
            PurchaseOrder po = new PurchaseOrder();
            po.POId = p.POId;
            po.QRCodeShortURL = p.QRCodeShortURL;
            po.QRCodeId = p.QRCodeId;
            po.PurchaseOrderNumber = p.PurchaseOrderNumber;
            po.GroupQRCode = p.GroupQRCode;
            po.Profile = (p.ProfileId.HasValue ? ProfileRepository.List().Where(x => x.Id == p.ProfileId.Value).First() : null);
            po.Group = (p.GroupId.HasValue ? GroupRepository.List().Where(x => x.Id == p.GroupId.Value).First() : null);
            po.Vendor = (p.VendorId.HasValue ? VendorRepository.List().Where(x => x.Id == p.VendorId.Value).First() : null);

            return po;
        }
        public ActionResult Details([Bind(Include="LineItems")] int id, PurchaseOrder po)
        {
            try
            {
                if (po.POId != 0)
                {
                    return RedirectToAction("Index");
                }

                return View(po);
            }
            catch
            {
                return View(po);
            }
        }
        // GET: /QRCode/Build
        public ActionResult Build(int numToBuild)
        {
            PurchaseOrderRepository rep = new PurchaseOrderRepository();
            List<string> shortURLs = new List<string>();

            for (int i = 0; i < numToBuild; i++)
            {
                PurchaseOrder po = new PurchaseOrder();
                po = rep.Save(po);

                string buildURL = "http://qr.tbs.io/qr/build?entityid=14&poid=" + po.POId.ToString() + "&url=true";
                string buildResponse = CallURL(buildURL);
                string qrCodeShortURL = buildResponse.Substring(buildResponse.LastIndexOf('?') + 3);
                qrCodeShortURL = qrCodeShortURL.Remove(qrCodeShortURL.LastIndexOf('"'));
                po.QRCodeShortURL = qrCodeShortURL;

                po = rep.Save(po);
                shortURLs.Add(po.QRCodeShortURL);
            }

            return RedirectToAction("Index");
        }
        public ActionResult Scan(PurchaseOrder po)
        {
            if (po.PurchaseOrderNumber > 0)
            {
                //associate QR Code to PO
                try
                {
                    if (ModelState.IsValid)
                    {
                        po = PurchaseOrderRepository.Save(po);

                        return RedirectToAction("Index");
                    }
                }
                catch (Exception ex)
                {
                    return View("Error", new HandleErrorInfo(ex, "PurchaseOrder", "Scan"));
                }
            }

            return View(po);
        }