Пример #1
0
 public void UpdateDatabase(Backer backer, Startup startup, FundAccount fund)
 {
     trickle.UpdateFundAccount(fund);
     trickle.UpdateBacker(backer);
     trickle.UpdateStartup(startup);
     trickle.CreateDeposit(fund);
     trickle.UpdateChain(backer, startup, fund, block);
 }
Пример #2
0
 public void PercentageTrickle(FundAccount fund, Startup start, Backer backer)
 {
     if (fund.hasCapped == false &
         fund.TotalDonated <= (fund.TrickleCap - fund.TrickleAmount))
     {
         Trickle(fund, start, backer);
     }
     CheckMilestones(fund);
 }
Пример #3
0
        public void MilestoneTrickle(FundAccount fund, Startup startup, Backer backer)
        {
            var milestoneList = trickle.GetMilestoneByStartupID(startup.ID);

            foreach (Milestone mile in milestoneList)
            {
                if (mile.Fulfilled == true & mile.FulfilledCompleted == false)
                {
                    Trickle(fund, startup, backer);
                    mile.FulfilledCompleted = true;
                }
            }
        }
Пример #4
0
 public void InsertFundAccount(FundAccount fund)
 {
     try
     {
         using (var context = new BlockContext())
         {
             context.FundAccount.Add(fund);
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Пример #5
0
        public void CheckMilestones(FundAccount fund)
        {
            var milestoneList = trickle.GetMilestoneByStartupID(fund.StartupID);

            foreach (Milestone mile in milestoneList)
            {
                if (mile.Fulfilled == true & mile.FulfilledCompleted == false)
                {
                    fund.TotalDonated += fund.Remainder;
                    fund.Remainder     = 0;
                    fund.hasCapped     = true;
                    trickle.UpdateFundAccount(fund);
                }
            }
        }
Пример #6
0
        public async Task <IActionResult> Bind([FromBody] BindInfo bindInfo)
        {
            var name     = bindInfo.AdminName;
            var password = bindInfo.AdminPassword;
            var thisUser = await(from u in MyDbContext.Administrators where u.Name.Equals(name) select u).ToArrayAsync();

            if (thisUser.Length == 0)
            {
                throw new ActionResultException(HttpStatusCode.Unauthorized, "no right");
            }
            var storedPassword = thisUser[0].Password;

            if (password.Equals(storedPassword))
            {
                var fundsAccounts = MyDbContext.FundAccounts;
                var thisAccount   = await(from a in MyDbContext.SecuritiesAccounts where a.Id.Equals(bindInfo.stock_account) select a).FirstOrDefaultAsync();
                if (thisAccount == null || thisAccount.AccountStatus == "a")
                {
                    throw new ActionResultException(HttpStatusCode.BadRequest, "The securities account is not valid");
                }
                var thisFundAccount = await(from f in MyDbContext.FundAccounts where f.AccountId.Equals(bindInfo.stock_account) select f).FirstOrDefaultAsync();
                if (thisFundAccount != null && thisFundAccount.AccountStatus != "a")
                {
                    throw new ActionResultException(HttpStatusCode.BadRequest, "The securities account is already binded with a fund account");
                }
                else if (thisFundAccount != null)
                {
                    thisFundAccount.AccountStatus = "n"; // 找回资金账户
                    MyDbContext.FundAccounts.Update(thisFundAccount);
                    await MyDbContext.SaveChangesAsync();

                    return(Ok(thisFundAccount));
                }

                var timestamp        = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
                var id               = (timestamp + 3160103827).ToString();
                MD5 md5              = new MD5CryptoServiceProvider();
                var initial_password = bindInfo.password;
                var newFundAccount   = new FundAccount(id, bindInfo.stock_account, initial_password);
                fundsAccounts.Add(newFundAccount);
                await MyDbContext.SaveChangesAsync();

                return(Ok(newFundAccount));
            }
            throw new ActionResultException(HttpStatusCode.Unauthorized, "no right");
        }
Пример #7
0
        public void Trickle(FundAccount fund, Startup startup, Backer backer)
        {
            if (fund.TotalDonated >= fund.TrickleCap)
            {
                fund.hasCapped = true;
                trickle.UpdateFundAccount(fund);
            }

            if (fund.TotalMoney >= fund.TrickleAmount && fund.hasCapped == false)
            {
                decimal bitcoin = currency.FiatToBTC("USD", fund.TrickleAmount);
                TransactionBTC.SendTransaction(bitcoin, startup.BTCAddress);
                startup.TotalReceived += fund.TrickleAmount;
                fund.TotalDonated     += fund.TrickleAmount;
                backer.TotalMoney     -= fund.TrickleAmount;
                fund.TotalMoney       -= fund.TrickleAmount;
                UpdateDatabase(backer, startup, fund);
            }
        }
Пример #8
0
        public void CreateDeposit(FundAccount fund)
        {
            var deposit = new Deposit
            {
                StartupID = fund.StartupID,
                BackerID  = fund.BackerID,
                Date      = DateTime.UtcNow,
                Amount    = fund.TrickleAmount
            };

            try
            {
                using (var context = new BlockContext())
                {
                    context.Deposits.Add(deposit);
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Пример #9
0
 public FundAccount Insert(FundAccount fund)
 {
     return(_fundAccountRepository.Add(fund));
 }
Пример #10
0
 public void UpdateChain(Backer back, Startup start, FundAccount fund, Blockchain block)
 {
     block.AddBlock(new Block(DateTime.Now, null, $"Sender: {start.Name}, Receiver: {back.Name} ,Amount: {fund.TrickleAmount}"));
     //Console.WriteLine(JsonConvert.SerializeObject(block, Formatting.Indented));
 }