Example #1
0
        public List <Asset> AddList(List <Asset> assets)
        {
            //Will check the TagNo of ProductType, but to get it, must first Get the full info of one PurchaseItem.
            PurchaseItem purchaseItem = repositoryPurchaseItem.FindById(assets[0].PurchaseItemID);
            string       tagRef       = purchaseItem.Product.ProductType.TagNo;

            //Get the latest used AssetTag from the same TagRef (ProductType)
            string assetMaxTagNo = repository.FindMaxTagNo(tagRef);


            var index = 1;

            foreach (var item in assets)
            {
                if (assetMaxTagNo == null)
                {
                    //Create a new AssetTag for that particular TagRef
                    item.AssetTag = "AUT" + index.ToString().PadLeft(5, '0') + tagRef;
                }
                else
                {
                    //Increase the number of last used AssetTag number.
                    long newTagNo = index + long.Parse(assetMaxTagNo.Substring(3, 5));

                    //Generate the new AssetTag
                    item.AssetTag = "AUT" + newTagNo.ToString().PadLeft(5, '0') + tagRef;
                }

                ////Add QR Code only with the AssetTag numer and pok, roduct name???
                ////string txtChar = " - ";
                //string txtQrCode = "AssetTag: " + item.AssetTag;
                //item.QrCode = QrCodeGenerator(txtQrCode);

                ////Remark: if we need to have the full QR-code, than need create it after save all records, generate them and save them again.

                index++;
            }
            //Don't need to return to assets list as program does it automatically!

            //Will save the List Asset to the database and return it back with AssetID's.
            assets = repository.AddList(assets);


            //To create the QR-code
            foreach (var item in assets)
            {
                //Go first to define de text and then generates & return the QR Code image
                item.QrCode = TxtQrCodeGenerator(item.AssetID);
            }

            assets = repository.UpdateList(assets);

            return(assets);
        }