public TransactionCollection getPaymentHistory(string usertoken)
        {
            TransactionCollection TransactionCollection = new TransactionCollection();

            Business.ApplicationService.transactions[] alltransactionscollection = getAllTransactionItems(usertoken);
            AccountCollection allaccounts = new PTAccount().GetUserAccounts(usertoken);
            int i = 1;

            foreach (Business.ApplicationService.transactions item in alltransactionscollection.GroupBy(p => p.categoryid).Select(g => g.First()))
            {
                AccountgroupCollection accgroup = allaccounts.accountcollection.Where(m => m.categoryid == item.categoryid).First();

                Transactiongroupcollection temptransactiongroupcollection = new Transactiongroupcollection();



                List <Business.ApplicationService.transactions> resulttransactions = alltransactionscollection.Where(p => p.categoryid == item.categoryid).ToList();
                foreach (Business.ApplicationService.transactions subitem in resulttransactions)
                {
                    try
                    {
                        if (subitem.ispaid)
                        {
                            PTAccount       acc = accgroup.accounts.Where(n => n.accountId == subitem.toaccountid).First();
                            TransactionItem temptransactionItem = new TransactionItem();
                            temptransactionItem.transactionid   = subitem.transactionid;
                            temptransactionItem.accountId       = subitem.toaccountid;
                            temptransactionItem.accountName     = acc.accountName;
                            temptransactionItem.accounttype     = acc.accounttype;
                            temptransactionItem.budgetamount    = (float)Convert.ToDouble(subitem.budget);
                            temptransactionItem.paidamount      = (float)Convert.ToDouble(subitem.paidamount);
                            temptransactionItem.categoryid      = subitem.categoryid;
                            temptransactionItem.categoryname    = acc.categoryname;
                            temptransactionItem.toaccountid     = subitem.toaccountid;
                            temptransactionItem.fromaccountid   = subitem.fromaccountid;
                            temptransactionItem.paymentmode     = subitem.paymentmode;
                            temptransactionItem.createddate     = subitem.createddate;
                            temptransactionItem.deleted         = false;
                            temptransactionItem.description     = subitem.description;
                            temptransactionItem.duemonth        = subitem.duemonth;
                            temptransactionItem.duedate         = subitem.duedate;
                            temptransactionItem.paiddate        = 0;// subitem.paiddate;
                            temptransactionItem.paidmonth       = subitem.paidmonth;
                            temptransactionItem.paidyear        = subitem.paidyear;
                            temptransactionItem.modifieddate    = subitem.modifieddate;
                            temptransactionItem.providerid      = acc.providerid;
                            temptransactionItem.providername    = acc.providername;
                            temptransactionItem.recurrence      = subitem.recurrence;
                            temptransactionItem.subcatid        = subitem.subcategoryid;
                            temptransactionItem.userid          = subitem.userid;
                            temptransactionItem.transactiondate = subitem.transactiondate;

                            temptransactiongroupcollection.groupitems.Add(temptransactionItem);
                        }
                        else
                        {
                        }
                    }
                    catch (Exception e)
                    {
                        string message = e.Message;
                    }
                }

                if (temptransactiongroupcollection.groupitems.Count > 0)
                {
                    temptransactiongroupcollection.categoryid   = item.categoryid;
                    temptransactiongroupcollection.categoryname = accgroup.categoryname;
                    TransactionCollection.groupcollection.Add(temptransactiongroupcollection);
                }
                else
                {
                }
            }
            return(TransactionCollection);
        }
        public TransactionCollection getTransactions(string usertoken)
        {
            TransactionCollection TransactionCollection = new TransactionCollection();

            Business.ApplicationService.transactions[] alltransactionscollection = getAllTransactionItems(usertoken);
            AccountCollection allaccounts = new PTAccount().GetUserAccounts(usertoken);
            int i = 1;
            foreach (Business.ApplicationService.transactions item in alltransactionscollection.GroupBy(p => p.categoryid).Select(g => g.First()))
            {
                AccountgroupCollection accgroup = allaccounts.accountcollection.Where(m => m.categoryid == item.categoryid).First();

                Transactiongroupcollection temptransactiongroupcollection = new Transactiongroupcollection();

                List<Business.ApplicationService.transactions> resulttransactions = alltransactionscollection.Where(p => p.categoryid == item.categoryid).ToList();
                foreach (Business.ApplicationService.transactions subitem in resulttransactions)
                {
                    try
                    {
                        PTAccount acc = accgroup.accounts.Where(n => n.accountId == subitem.toaccountid).First();
                        TransactionItem temptransactionItem = new TransactionItem();
                        temptransactionItem.transactionid = subitem.transactionid;
                        temptransactionItem.accountId = subitem.toaccountid;
                        temptransactionItem.accountName = acc.accountName;
                        temptransactionItem.accounttype = acc.accounttype;
                        temptransactionItem.budgetamount = (float)Convert.ToDouble(subitem.budget);
                        temptransactionItem.paidamount = (float)Convert.ToDouble(subitem.paidamount);
                        temptransactionItem.categoryid = subitem.categoryid;
                        temptransactionItem.categoryname = acc.categoryname;
                        temptransactionItem.toaccountid = subitem.toaccountid;
                        temptransactionItem.fromaccountid = subitem.fromaccountid;
                        temptransactionItem.paymentmode = subitem.paymentmode;
                        temptransactionItem.createddate = subitem.createddate;
                        temptransactionItem.deleted = false;
                        temptransactionItem.description = subitem.description;
                        temptransactionItem.duemonth = subitem.duemonth;
                        temptransactionItem.duedate = subitem.duedate;
                        temptransactionItem.paiddate = 0;// subitem.paiddate;
                        temptransactionItem.paidmonth = subitem.paidmonth;
                        temptransactionItem.paidyear = subitem.paidyear;
                        temptransactionItem.modifieddate = subitem.modifieddate;
                        temptransactionItem.providerid = acc.providerid;
                        temptransactionItem.providername = acc.providername;
                        temptransactionItem.recurrence = subitem.recurrence;
                        temptransactionItem.subcatid = subitem.subcategoryid;
                        temptransactionItem.userid = subitem.userid;
                        temptransactionItem.transactiondate = subitem.transactiondate;

                        temptransactiongroupcollection.groupitems.Add(temptransactionItem);
                    }
                    catch(Exception e)
                    {
                        string message = e.Message;
                    }

                }

                if (temptransactiongroupcollection.groupitems.Count > 0)
                {
                    temptransactiongroupcollection.categoryid = item.categoryid;
                    temptransactiongroupcollection.categoryname = accgroup.categoryname;
                    TransactionCollection.groupcollection.Add(temptransactiongroupcollection);
                }
                else
                {

                }

            }
            return TransactionCollection;
        }