public string AddDeal(Deal deal, string accountNumber, int codePin) { var dataAc = db.Accounts.ToList(); foreach (var item in dataAc) { if (accountNumber == item.AccountNumber) { if (codePin == item.CodePin) { if (deal.DealMoney < item.Money) { deal.Account_ID = accountNumber; deal.TransactionFees = CheckPhanTram(deal.DealMoney, deal.TransactionFees); Account ac1 = db.Accounts.Where(x => x.AccountNumber == accountNumber).First(); ac1.Money = ac1.Money - deal.DealMoney; db.Entry(ac1).State = EntityState.Modified; Account ac2 = db.Accounts.Where(x => x.AccountNumber == deal.RecipientAccount).First(); ac2.Money = ac2.Money + (deal.DealMoney - deal.TransactionFees); db.Entry(ac2).State = EntityState.Modified; db.Deals.Add(deal); db.SaveChanges(); return("Giao dich thanh cong"); } else { return("So du tai khoan khong du de thuc hien giao dich"); } } else { return("Mat khau khong dung"); } } else { return("Tai khoan khong dung"); } } return("Tai khoan khong ton tai"); }
public void AddAccount(Account account) { db.Accounts.Add(account); db.SaveChanges(); }