public AccountCollection GetUserAccounts(string usertoken)
        {
            Business.ApplicationService.AppServiceClient appclient   = new Business.ApplicationService.AppServiceClient();
            Business.ApplicationService.accounts[]       appaccounts = appclient.Getaccounts(usertoken);

            AccountCollection AccountCollection = new Models.AccountCollection();


            List <AccountgroupCollection> accountgroupcollection = new List <AccountgroupCollection>();


            foreach (Business.ApplicationService.accounts item in appaccounts.GroupBy(p => p.categoryid).Select(g => g.First()))
            {
                AccountgroupCollection temgroup = new AccountgroupCollection();

                temgroup.categoryid   = item.categoryid;
                temgroup.categoryname = item.categoryname;
                temgroup.userid       = item.userid;
                List <Business.ApplicationService.accounts> resultaccounts = appaccounts.Where(p => p.categoryid == item.categoryid).ToList();
                foreach (Business.ApplicationService.accounts subitem in resultaccounts)
                {
                    PTAccount tempaccount = new PTAccount();
                    tempaccount.accountId    = subitem.accountid;
                    tempaccount.accountName  = subitem.accountname;
                    tempaccount.accounttype  = subitem.accounttype;
                    tempaccount.amount       = (float)Convert.ToDouble(subitem.amount);
                    tempaccount.uniqueid     = subitem.unid;
                    tempaccount.categoryid   = subitem.categoryid;
                    tempaccount.categoryname = subitem.categoryname;
                    tempaccount.createddate  = subitem.createddate;
                    tempaccount.deleted      = false;
                    tempaccount.description  = subitem.description;
                    tempaccount.duemonth     = subitem.duemonth;
                    tempaccount.duedate      = subitem.duedate;
                    tempaccount.modifieddate = subitem.modifieddate;
                    tempaccount.providerid   = subitem.providerid;
                    tempaccount.providername = subitem.providername;
                    tempaccount.recurrence   = subitem.recurrence;
                    tempaccount.subcatid     = subitem.subcategoryid;
                    tempaccount.userid       = subitem.userid;
                    tempaccount.global       = subitem.global;
                    tempaccount.initial      = subitem.initial;
                    tempaccount.codes        = subitem.codes;
                    temgroup.accounts.Add(tempaccount);
                }
                accountgroupcollection.Add(temgroup);
            }

            AccountCollection.requestedtime     = DateTime.Now.ToString();
            AccountCollection.accountcollection = accountgroupcollection;
            return(AccountCollection);
        }
        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 PTAccount CreateAccount(string accountname, string userid, string accounttype, string subcatid, string description, string providerid, string providername, float amount, string duedate, string recurrence)
        {
            PTAccount CreatedAccount = new PTAccount();

            return(CreatedAccount);
        }
        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;
        }
        public AccountCollection GetUserAccounts(string usertoken)
        {
            Business.ApplicationService.AppServiceClient appclient = new Business.ApplicationService.AppServiceClient();
            Business.ApplicationService.accounts[] appaccounts = appclient.Getaccounts(usertoken);

            AccountCollection AccountCollection = new Models.AccountCollection();

            List<AccountgroupCollection> accountgroupcollection = new List<AccountgroupCollection>();

            foreach (Business.ApplicationService.accounts item in appaccounts.GroupBy(p => p.categoryid).Select(g => g.First()))
            {
                AccountgroupCollection temgroup = new AccountgroupCollection();

                temgroup.categoryid = item.categoryid;
                temgroup.categoryname = item.categoryname;
                temgroup.userid = item.userid;
                List<Business.ApplicationService.accounts> resultaccounts = appaccounts.Where(p => p.categoryid == item.categoryid).ToList();
                foreach (Business.ApplicationService.accounts subitem in resultaccounts)
                {

                    PTAccount tempaccount = new PTAccount();
                    tempaccount.accountId = subitem.accountid;
                    tempaccount.accountName = subitem.accountname;
                    tempaccount.accounttype = subitem.accounttype;
                    tempaccount.amount = (float)Convert.ToDouble(subitem.amount);
                    tempaccount.uniqueid = subitem.unid;
                    tempaccount.categoryid = subitem.categoryid;
                    tempaccount.categoryname = subitem.categoryname;
                    tempaccount.createddate = subitem.createddate;
                    tempaccount.deleted = false;
                    tempaccount.description = subitem.description;
                    tempaccount.duemonth = subitem.duemonth;
                    tempaccount.duedate = subitem.duedate;
                    tempaccount.modifieddate = subitem.modifieddate;
                    tempaccount.providerid = subitem.providerid;
                    tempaccount.providername = subitem.providername;
                    tempaccount.recurrence = subitem.recurrence;
                    tempaccount.subcatid = subitem.subcategoryid;
                    tempaccount.userid = subitem.userid;
                    tempaccount.global = subitem.global;
                    tempaccount.initial = subitem.initial;
                    tempaccount.codes = subitem.codes;
                    temgroup.accounts.Add(tempaccount);

                }
                accountgroupcollection.Add(temgroup);
            }

            AccountCollection.requestedtime = DateTime.Now.ToString();
            AccountCollection.accountcollection = accountgroupcollection;
            return AccountCollection;
        }
        public PTAccount CreateAccount(string accountname, string userid, string accounttype, string subcatid, string description, string providerid, string providername, float amount, string duedate, string recurrence)
        {
            PTAccount CreatedAccount = new PTAccount();

            return CreatedAccount;
        }