I am consuming Wcf REST Service into Angular JS Application. I am Facing some error with the linq Query . I got the follwing error on follwing line on debugging mode ..The underlying provider failed on Commit.
ReciverAccount.Account_Balance += Convert.ToDecimal(mopneyTransfer.Amount1);
dbContextTransaction.Commit();
I ma trying to send money one account to another account and account balance on both account should be updated and insert the respective record into database but i can not do it ..
Here is the Error message on debug Mode .
System.Data.Entity.Core.EntityException occurred
HResult=0x80131501
Message=The underlying provider failed on Commit.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
Inner Exception 1:
ArgumentNullException: Value cannot be null.
Here is me linq query ..
public bool MoneyTranfer(MoneyTransfer mopneyTransfer)
{
//int amount = System.Convert.ToInt32(mopneyTransfer.Amount);
//int amount1 = System.Convert.ToInt32(mopneyTransfer.Amount1);
int ID = Convert.ToInt32(mopneyTransfer.Sender_Account_No);
var foundAccount = (from a in ctx.Current_Account_Details
where a.Account_Number.Equals(ID)
select a).Distinct().FirstOrDefault();
if (foundAccount != null)
{
//if (amount > 0)
//{
using (var dbContextTransaction = ctx.Database.BeginTransaction())
{
var senderAccount = (from a in ctx.Current_Account_Details
where a.Account_Number.Equals(ID)
select a).Distinct().FirstOrDefault();
if (senderAccount != null)
{
senderAccount.Account_Balance -= Convert.ToDecimal(mopneyTransfer.Amount);
dbContextTransaction.Commit();
ctx.SaveChanges();
}
int ID1 = Convert.ToInt32(mopneyTransfer.Receiver_Account_No);
var ReciverAccount = (from a in ctx.Current_Account_Details
where a.Account_Number.Equals(ID1)
select a).Distinct().FirstOrDefault();
if (ReciverAccount != null)
{
ReciverAccount.Account_Balance += Convert.ToDecimal(mopneyTransfer.Amount1);
dbContextTransaction.Commit();
ctx.SaveChanges();
Current_Account_Deposit cad = new Current_Account_Deposit();
cad.Account_Number = Convert.ToInt32(mopneyTransfer.Sender_Account_No);
cad.Account_Holder_Name = mopneyTransfer.Sender_Name;
cad.Amount = Convert.ToDecimal(mopneyTransfer.Amount);
cad.Sort_Code = mopneyTransfer.Sender_Sort_Code;
cad.Transcation_Type = mopneyTransfer.Transcation_Type;
cad.Date = mopneyTransfer.Date;
ctx.Current_Account_Deposit.Add(cad);
ctx.SaveChanges();
Current_Account_Withdraw caw = new Current_Account_Withdraw();
caw.Account_Number = Convert.ToInt32(mopneyTransfer.Receiver_Account_No);
caw.Account_Holder_Name = mopneyTransfer.Receiver_Name;
caw.Amount = Convert.ToDecimal(mopneyTransfer.Amount1);
caw.Sort_Code = mopneyTransfer.Receiver_Sort_Code;
caw.Transcation_Type = mopneyTransfer.Transcation_Type1;
caw.Date = mopneyTransfer.Date1;
ctx.Current_Account_Withdraw.Add(caw);
ctx.SaveChanges();
}
else
{
dbContextTransaction.Rollback();
return false;
}
}
} return false;
}
Any feedback or suggestion will be great help .
User contributions licensed under CC BY-SA 3.0