Ejemplo n.º 1
0
        public async Task <Tuple <bool, string> > AddUserRequestAsync(LoginDetails details)
        {
            RhodeITDB       db = new RhodeITDB();
            AddUserFunction addUserFunction = new AddUserFunction
            {
                FromAddress        = details.Ethereum_Address,
                Gas                = Variables.gas,
                Studentno_staff_no = details.User_ID
            };
            string receipt = "0x";
            bool   exists  = await UserExistsRequestAndWaitForReceiptAsync(details.Ethereum_Address).ConfigureAwait(false);

            if (exists)
            {
                db.StoreTransactionReceipt(new Models.TransactionReceipt {
                    Receipt = receipt, Activity = "LoggedIn"
                });
            }
            else
            {
                receipt = await ContractHandler.SendRequestAsync(addUserFunction).ConfigureAwait(false);

                exists = await UserExistsRequestAndWaitForReceiptAsync(details.Ethereum_Address).ConfigureAwait(false);

                db.StoreTransactionReceipt(new Models.TransactionReceipt {
                    Receipt = receipt, Activity = "Registered"
                });
                db.UpdateLoginDetails(details);
            }
            return(new Tuple <bool, string>(exists, receipt));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// @dev function that allows user to login this function also adds users to the smartcontracts storage users dont not need to register university credentials will be sufficient
        /// </summary>
        /// <param name="studentNo">student number</param>
        /// <param name="password">password</param>
        /// <returns>if the login was succefull or not</returns>
        public async Task RegisterStudent(LoginDetails details)
        {
            rhodeITDB       = new RhodeITDB();
            details.User_ID = details.User_ID.ToLower();
            string Thash = "";
            Tuple <bool, string> results = await SmartContractFunctions.AddUserRequestAsync(details).ConfigureAwait(false);

            Thash = results.Item2;
            details.TransactionHash = Thash;
            rhodeITDB.UpdateLoginDetails(details);
        }
        public void Purchase_Ride_Credits()
        {
            RhodeITService rhodeITServices = new RhodeITService();
            RhodeITDB      db     = new RhodeITDB();
            IUserDialogs   dialog = UserDialogs.Instance;

            dialog.ShowLoading("Purchasing Ride Credits...");
            try
            {
                bool result = int.TryParse(amount.Text, out int rideCredit);
                if (!result)
                {
                    throw new InvalidNumberException("Invalid");
                }
                try
                {
                    if (rideCredit <= 0)
                    {
                        throw new InvalidNumberException("");
                    }
                    else
                    {
                        Details = db.GetUserDetails();
                        rhodeITServices.UpdateCreditRequestAsync(Details.Ethereum_Address, rideCredit).ConfigureAwait(false);
                        Details.RideCredits += rideCredit;
                        RhodesDataBase.ChargeUserRideCreditBalanceToAccount(Details).ConfigureAwait(false);
                        db.UpdateLoginDetails(Details);
                        dialog.HideLoading();
                        dialog.Alert(string.Format("Succesfully recharged ride credits with {0}", rideCredit), "Success", "OK");
                    }
                }
                catch (Exception e)
                {
                    dialog.HideLoading();
                    PopupLayout.Dismiss();
                    Console.WriteLine("Error whilst purcasing credits: " + e.Message);
                    dialog.Alert("Something went wrong whilst purchasing credit", "Insufficient Funds", "OK");
                }
            }
            catch (InvalidNumberException e)
            {
                dialog.HideLoading();
                PopupLayout.Dismiss();
                Console.WriteLine("Error whilst purcasing credits: " + e.Message);
                dialog.Alert("Please ensure you entered a valid number e.g. 12", "Invalid Number", "OK");
            }
        }