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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Guest UserRank #259 · 9.8K reputationPosted Jul 15, 2014, 7:16 PM EDT
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();
}
Sandra F14 reputationPosted Jul 15, 2014, 9:05 PM EDT
To Login need to use c100 and password is password100.
thank you for advance...
Guest UserRank #259 · 9.8K reputationPosted Jul 15, 2014, 9:23 PM EDT
Sandra F14 reputationPosted Jul 15, 2014, 9:40 PM EDT
Sandra F14 reputationPosted Jul 15, 2014, 10:40 PM EDT
Sandra F14 reputationPosted Jul 16, 2014, 6:24 PM EDT
Guest UserRank #259 · 9.8K reputationPosted Jul 20, 2014, 10:30 PM EDT
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();
}
Guest UserRank #259 · 9.8K reputationPosted Jul 23, 2014, 10:22 AM EDT