public bool donateMoneyToAllDisasters(decimal totalPrice, int userBankId) { BankAccountB userAcc = new BankAccountB(); BankAccountDAL bankDal = new BankAccountDAL(); DisasterDAL disasterDal = new DisasterDAL(); List <DisasterB> allDis = new List <DisasterB>(); userAcc = bankDal.GetBankAccountById(userBankId); decimal moneyForOneDisaster = 0; if (userAcc.Amount < totalPrice) { return(false); } userAcc.Amount = userAcc.Amount - totalPrice; bankDal.Update(userAcc); allDis = disasterDal.GetAllDisasters(); moneyForOneDisaster = totalPrice / allDis.Count; foreach (DisasterB dis in allDis) { BankAccountB disAcc = new BankAccountB(); disAcc = bankDal.GetBankAccountById(dis.DisasterBankAccountId); disAcc.Amount = disAcc.Amount + moneyForOneDisaster; bankDal.Update(disAcc); } return(true); }
public bool donateToSpecificDisaster(decimal amount, BankAccountB userBankAcc, BankAccountB disasterBankAcc) { BankAccountDAL bankDal = new BankAccountDAL(); userBankAcc.Amount = userBankAcc.Amount - amount; bool userUpdate = bankDal.Update(userBankAcc); disasterBankAcc.Amount = disasterBankAcc.Amount + amount; bool disasterUpdate = bankDal.Update(disasterBankAcc); if (userUpdate == false || disasterUpdate == false) { return(false); } return(true); }