Пример #1
0
 Guid IMedicineBatchRepository.CreateAndReturnId(MedicineBatch medicineBatch)
 {
     (this as IMedicineBatchRepository).Create(medicineBatch);
     return(medicineBatch.Id);
 }
Пример #2
0
 void IMedicineBatchRepository.Update(MedicineBatch medicineBatch)
 {
     dbContext.MedicineBatches.Update(medicineBatch);
     dbContext.SaveChanges();
 }
Пример #3
0
        void IMedicineBatchBackgroundJob.WaitForTransactionToSuccessThenFinishCreatingMedicineBatch(MedicineBatch medicineBatch)
        {
            bool isTransactionSuccess = false;

            do
            {
                var receipt = ethereumService.GetTransactionReceipt(medicineBatch.TransactionHash).Result;
                if (receipt == null)
                {
                    continue;
                }
                if (receipt.Status.Value == (new HexBigInteger(1)).Value)
                {
                    isTransactionSuccess = true;
                    var contractAddress = ethereumService.GetObjectContractAddress(medicineBatch.Id).Result;
                    medicineBatch.ContractAddress   = contractAddress;
                    medicineBatch.TransactionStatus = Models.Database.TransactionStatuses.Success;
                    medicineBatchRepository.Update(medicineBatch);

                    var medicineBatchContract = ethereumService.GetContract(MedicineBatchAbi, medicineBatch.ContractAddress);
                    var updateFunction        = ethereumService.GetFunction(medicineBatchContract, EthereumFunctions.UpdateMedicineBatchInformation);
                    var updateReceipt         = updateFunction.SendTransactionAndWaitForReceiptAsync(
                        ethereumService.GetEthereumAccount(),
                        new HexBigInteger(6000000),
                        new HexBigInteger(Nethereum.Web3.Web3.Convert.ToWei(50, UnitConversion.EthUnit.Gwei)),
                        new HexBigInteger(0),
                        functionInput: new object[] {
                        medicineBatch.MedicineId.ToString(),
                        medicineBatch.BatchNumber,
                        medicineBatch.ManufacturerId.ToString(),
                        medicineBatch.Quantity,
                        medicineBatch.Unit,
                        medicineBatch.ManufactureDate.ToUnixTimestamp(),
                        medicineBatch.ExpiryDate.ToUnixTimestamp()
                    }).Result;
                }
            }while (isTransactionSuccess != true);
        }