Пример #1
0
        public MBarcode Apply(MBarcode dat)
        {
            MBarcode bc = new MBarcode();
            bc.BatchNo = dat.BatchNo;
            bc.Url = dat.Url;
            bc.Product = dat.Product;
            bc.GeneratedDate = DateTime.Now;
            bc.IsActivated = false;
            bc.Path = dat.Path;

            bc.CompanyWebSite = dat.CompanyWebSite;
            bc.Barcode = dat.Barcode;
            bc.Product = dat.Product;

            if (IsMigration(dat))
            {
                bc.SerialNumber = dat.SerialNumber;
                bc.Pin = dat.Pin;
                bc.PayloadUrl = dat.PayloadUrl;
            }
            else
            {
                bc.SerialNumber = RandomUtils.RandomStringNum(10);
                bc.Pin = RandomUtils.RandomStringNum(10);
                bc.PayloadUrl = string.Format("{0}/verification/{1}/{2}/{3}", bc.Url, bc.Path, bc.SerialNumber, bc.Pin);
            }

            string path = BarcodeUtils.BuildBarcodePath("barcodes", bc.SerialNumber, bc.Pin);

            var ctx = GetNoSqlContext();
            ctx.PostData(path, bc);

            return bc;
        }
Пример #2
0
        private bool IsBarcodeExisting(string serialNumber, string pin)
        {
            string   bcPath = BarcodeUtils.BuildBarcodePath("barcodes", serialNumber, pin);
            MBarcode bc     = ctx.GetObjectByKey <MBarcode>(bcPath);

            if (bc != null)
            {
                return(true);
            }
            return(false);
        }
        public int Apply(MRegistration dat)
        {
            ValidateRegistration(dat);

            string   barcode = string.Format("{0}-{1}", dat.SerialNumber, dat.Pin);
            MBarcode bc      = null;
            string   bcPath  = null;
            var      ctx     = GetNoSqlContext();

            if ((dat.SerialNumber.Length > 3) && (dat.Pin.Length > 3))
            {
                bcPath = BarcodeUtils.BuildBarcodePath("barcodes", dat.SerialNumber, dat.Pin);
                bc     = ctx.GetObjectByKey <MBarcode>(bcPath);
            }

            if (bc == null)
            {
                string msg = PostData(dat, barcode, "NOTFOUND", "Serial number and PIN not found [{0}]");
                throw (new ArgumentException(msg));
            }

            dat.RegistrationDate = DateTime.Now;
            dat.LastMaintDate    = DateTime.Now;

            ValidateActivation(dat, bc, barcode);

            //Update status back to barcode

            bc.IsActivated   = GetActivateFlag();
            bc.ActivatedDate = DateTime.Now;
            bc.LastMaintDate = DateTime.Now;
            ctx.PutData(bcPath, bc.Key, bc);

            PerformRegistrationAction(dat, barcode);

            return(0);
        }