示例#1
0
        public (decimal, string) CreateAccountHistory(AccountHistory accountHistory)
        {
            Account account = GetAccountByID(accountHistory.AccountID);

            if (account == null)
            {
                return(0, "Error");
            }
            account.Ballance = (accountHistory.Amount > 0)? account.Ballance + accountHistory.Amount : account.Ballance - accountHistory.Amount;
            dbcontext.Account.Add(account);
            dbcontext.Update(account);
            dbcontext.AccountHistory.Add(accountHistory);
            _ = dbcontext.SaveChanges();
            string succes = JsonConvert.SerializeObject(accountHistory);

            return(account.Ballance, "OK");
        }
示例#2
0
        public decimal UpdateAccount(AccountHistory accountHistory)
        {
            Account account = GetAccountByID(accountHistory.AccountID);

            if (account == null)
            {
                return(0);
            }
            account.Ballance = (accountHistory.Amount > 0) ? account.Ballance - accountHistory.Amount : account.Ballance + accountHistory.Amount;
            if (account.Ballance < 0)
            {
                return(0);
            }
            dbcontext.Account.Add(account);
            dbcontext.Update(account);
            dbcontext.AccountHistory.Add(accountHistory);
            dbcontext.SaveChanges();
            return(account.Ballance);
        }