async Task ITenantService.Update( Guid id, string name, string email, string address, string phoneNumber, string taxCode, string registrationCode, string certificates, TenantTypes type) { var tenant = tenantRepository.Get(id); if (tenant == null) { throw new ArgumentException("Id does not exist in the system.", nameof(id)); } tenant.Name = name; tenant.Email = email; tenant.PrimaryAddress = address; tenant.PhoneNumber = phoneNumber; tenant.TaxCode = taxCode; tenant.RegistrationCode = registrationCode; tenant.Certificates = certificates; tenant.Type = type; tenantRepository.Update(tenant); // Update the blockchain. var tenantContract = ethereumService.GetContract(TenantAbi, tenant.ContractAddress); var updateFunction = ethereumService.GetFunction(tenantContract, EthereumFunctions.UpdateTenantInformation); var updateReceipt = await updateFunction.SendTransactionAsync( ethereumService.GetEthereumAccount(), new HexBigInteger(6000000), new HexBigInteger(Nethereum.Web3.Web3.Convert.ToWei(20, UnitConversion.EthUnit.Gwei)), new HexBigInteger(0), functionInput : new object[] { tenant.Name, tenant.Email, tenant.PrimaryAddress, tenant.PhoneNumber, tenant.TaxCode, tenant.RegistrationCode, tenant.Certificates, (uint)tenant.Type }); }
private List <StudentModel> GetStudentProfile(TenantTypes tenantTypes) { if (tenantTypes == TenantTypes.Cal) { return(new List <StudentModel>() { new StudentModel() { City = "Oakville", LastName = "Borsuk", Name = "Alex" }, new StudentModel() { City = "Oakville", LastName = "Borsuk", Name = "Alex" }, new StudentModel() { City = "Oakville", LastName = "Borsuk", Name = "Alex" } }); } return(new List <StudentModel>() { new StudentModel() { City = "Toronto", LastName = "Borsuk", Name = "Alex" }, new StudentModel() { City = "Toronto", LastName = "Borsuk", Name = "Alex" }, new StudentModel() { City = "Toronto", LastName = "Borsuk", Name = "Alex" } }); }
async Task <Guid> ITenantService.Create( string name, string email, string address, string phoneNumber, string taxCode, string registrationCode, string certificates, TenantTypes type) { var function = ethereumService.GetFunction(EthereumFunctions.AddChainPoint); try { var tenant = new Tenant() { Name = name, Email = email, PrimaryAddress = address, PhoneNumber = phoneNumber, TaxCode = taxCode, RegistrationCode = registrationCode, Certificates = certificates, DateCreated = DateTime.UtcNow, Type = type }; Guid newTenantId = tenantRepository.CreateAndReturnId(tenant); var transactionHash = await function.SendTransactionAsync( ethereumService.GetEthereumAccount(), new HexBigInteger(4000000), new HexBigInteger(Nethereum.Web3.Web3.Convert.ToWei(50, UnitConversion.EthUnit.Gwei)), new HexBigInteger(0), functionInput : new object[] { newTenantId.ToString(), name, address, phoneNumber, taxCode, registrationCode }); tenant.TransactionHash = transactionHash; tenantRepository.Update(tenant); // Create auth0 user. var userRole = (type == TenantTypes.Manufacturer) ? "manufacturer" : (type == TenantTypes.Distributor ? "distributor" : (type == TenantTypes.Retailer ? "retailer" : "unknown")); var userAuth0 = auth0Service.CreateUser(newTenantId.ToString(), email, "123456789?a", userRole); BackgroundJob.Schedule <ITenantBackgroundJob>( backgroundJob => backgroundJob.WaitForTransactionToSuccessThenFinishCreatingTenant(tenant), TimeSpan.FromSeconds(3) ); return(newTenantId); } catch (Exception ex) { throw ex; } }