Hi,
I'm a student of TAFE. I created few tables as Login, Customer and Account. An Account table details as Account Detail as ID, Type and Balance
and i don't know how to transfer some amount between accounts.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Guest UserPosted Jul 15, 2014, 11:16 PM
in mvc4 you can have AccountDetailsController with PUT method which will leverage AccountDetail model to update data, e.g.,
Model
class AccountDetail
{
public int ID;
public int Type;
public float Balance;
}
AccountDetailsController
[HttpPut]
class AccountDetailsController : BaseClass //I assume this base class is leveraging any //framework for db update like PetaPoco
public void UpdateAccounts
{
AccountDetail ad=new AccountDetail();
ad = AccountDetail .FindByID(1);
ad.Balance = 222;
ad.Update();
}
Guest UserPosted Jul 23, 2014, 2:22 PM
Guest UserPosted Jul 21, 2014, 2:30 AM
So, what I understand is within same table you want to update data among different records ? Right.
This is simple problem where you can use UPDATE queries or any ORM (PetaPoco or Massive) to leverage Update() function?
The algo to do that is:
AccountDetailsController
[HttpPut]
class AccountDetailsController : BaseClass //I assume this base class is leveraging any //framework for db update like PetaPoco
public void UpdateAccounts(int id)
{
AccountDetail ad=new AccountDetail();
ad = AccountDetail .Find("select * from accounts where user_id=@0", id);
//this will give you all accounts for same user. Now you want to transfer funds, so you need input for that, I assume you've passed data in Request Headers
string baseAccountNo = Request.Header["baseAccount"];
string transferAccountNo = Request.Header["transferAccount"];
double transferAmt=Request.Header["amount"];
//get funds in base account
double baseAccountAmount = ad.Select(x=>x.accountNo==baseAccountNo).FirstOrDefault().Amount;
//check if baseAccountNo has required funds
if ( baseAccountAmount >=transferAmt) {
double amountInTransferAccount= ad.Select(x=>x.accountNo==transferAccountNo).FirstOrDefault().Amount;
amountInTransferAccount+=transferAmt;
ad.Select(x=>x.accountNo==baseAccountNo).FirstOrDefault().Amount -=transferAmt;
}
ad.Update();
}
Sandra FPosted Jul 16, 2014, 10:24 PM
Sandra FPosted Jul 16, 2014, 2:40 AM
Sandra FPosted Jul 16, 2014, 1:40 AM
Guest UserPosted Jul 16, 2014, 1:23 AM
Sandra FPosted Jul 16, 2014, 1:05 AM
To Login need to use c100 and password is password100.
thank you for advance...