private ResultModel BlockchainAndDB(ref ProductEthAddress_V prod_v)
        {
            string      product_key = prod_v.Product_Key;
            string      Private_key = prod_v.EthPrivateKey;
            string      Public_key  = prod_v.EthPublicKey;
            Decimal     Amount      = 0.00015m;
            ResultModel result      = new ResultModel();

            try
            {
                EthAddressesController ethac = new EthAddressesController();
                Decimal GetBalance           = Task.Run <Decimal>(async() => await ethac.GetAccountBalance(Public_key)).Result;
                if (Amount >= GetBalance)
                {
                    result._Result      = false;
                    result._ResultError = "No Sufficient Balance in ETH Account";

                    return(result);
                }

                Models.Transaction TR = Task.Run <Models.Transaction>(async() => await ethac.SendTransactionAndData(ethac.MasterEthPublicKey, Amount, product_key, Private_key)).Result;
                //Task.Run<Models.Transaction>(async () => await ethac.SendTransaction(ethac.MasterEthPublicKey, 0.00015m, prod_v.EthPrivateKey)).Result;
                TR.ProductID    = prod_v.Product_ID;
                TR.CreatedBy    = UserControl.UserID;
                TR.UserTypeID   = UserControl.UserTypeID;
                TR.EthAddressID = prod_v.EthAddressID ?? default(int);
                TR.CreatedDate  = DateTime.Now;
                db.Transactions.Add(TR);
                db.SaveChanges();

                var product_db = db.Products.Find(prod_v.Product_ID);
                product_db.UserID        = UserControl.UserID;
                product_db.TransactionID = TR.TransactionID;
                db.SaveChanges();

                result._ResultTransHash = TR.TransactionHash;
                result._Result          = true;

                prod_v.UserID        = product_db.UserID;
                prod_v.TransactionID = product_db.TransactionID;
            }
            catch (Exception ex)
            {
                result._Result      = false;
                result._ResultError = ex.Message;

                return(result);
            }

            return(result);
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "ProductId,ProductName,ProductKey,SerialNumber,ProductType,ProductDetail,ProductIsActive,ImagePath,ImageFile")] ProductModel prodM)
        {
            if (ModelState.IsValid)
            {
                Decimal Amount = 0.0002m;
                EthAddressesController ethac = new EthAddressesController();
                Decimal GetBalance           = Task.Run <Decimal>(async() => await ethac.GetAccountBalance()).Result;
                if (Amount >= GetBalance)
                {
                    return(View(prodM));
                }

                var ethadd = ethac.GenerateEthAddress();
                ethadd.CreatedBy   = UserControl.UserID;
                ethadd.CreatedDate = DateTime.Now;
                db.EthAddresses.Add(ethadd);
                db.SaveChanges();

                Models.Transaction TR = Task.Run <Models.Transaction>(async() => await ethac.SendTransactionAndData(ethadd.EthPublicKey, 0.0002m, prodM.ProductKey)).Result;
                //Task.Run<Models.Transaction>(async () => await ethac.SendTransaction(ethadd.EthPublicKey, 0.0002m)).Result;
                //TR.ProductID = product.Product_ID;
                TR.EthAddressID = ethadd.EthAddressID;
                TR.CreatedBy    = UserControl.UserID;
                TR.CreatedDate  = DateTime.Now;
                db.Transactions.Add(TR);
                db.SaveChanges();

                Product product = new Product
                {
                    Product_Name       = prodM.ProductName,
                    Product_Key        = prodM.ProductKey,
                    Serial_Num         = prodM.SerialNumber,
                    Product_Type       = prodM.ProductType,
                    Product_Detail     = prodM.ProductDetail,
                    IsActive           = prodM.ProductIsActive,
                    EthAddressID       = ethadd.EthAddressID,
                    FirstTransactionID = TR.TransactionID,
                    CreatedBy          = UserControl.UserID,
                    CreatedDate        = DateTime.Now
                };

                db.Products.Add(product);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(prodM));
        }