public string TranscationDetails(string Account_Number)
{
var accountNumber = int.Parse(Account_Number);//It could be better to use TryParse
List<AccountTransaction> accountTransactions = new List<AccountTransaction>();
using (HalifaxDatabaseEntities context = new HalifaxDatabaseEntities())
{
accountTransactions.AddRange(context.Current_Account_Deposit.Where(x => x.Account_Number == accountNumber).Select(w => new AccountTransaction
{
AccountNumber = w.Account_Number,
Deposit = 0,
Withdrawal = w.Amount,
Date = w.Date,
Fee = 0
}).ToList());
accountTransactions.AddRange(context.Current_Account_Withdraw.Select(d => new AccountTransaction
{
AccountNumber = d.Account_Number,
Deposit = d.Amount,
Withdrawal = 0,
Date = d.Date,
Fee = 0
}).OrderBy(r => r.Date).ToList());
accountTransactions.AddRange(context.Current_Account_Details.Select(e => new AccountTransaction
{
//You should perform same anonymous type which you want to concat
AccountNumber = e.Account_Number,
Deposit = e.Account_Balance,
Withdrawal = 0,
Date = null,
Fee = e.Account_Fees
}).ToList());
var inOut = accountTransactions;
var js = new System.Web.Script.Serialization.JavaScriptSerializer();
return js.Serialize(inOut); // return JSON string
}
}
public class AccountTransaction
{
public int AccountNumber { get; set; }
public decimal Deposit { get; set; }
public decimal Withdrawal { get; set; }
public string Date{ get; set; }
public decimal Fee { get; set; }
}