Example #1
0
 //get record based on id
 public PayerPayee PPRecord(int id)
 {
     using (var context = new FinanceEDMContainer())
     {
         return(context.PayerPayees.SingleOrDefault(e => e.PPId == id));
     }
 }
Example #2
0
 //get all records
 public List <PayerPayee> AllPPRecords()
 {
     using (var context = new FinanceEDMContainer())
     {
         return(context.PayerPayees.ToList());
     }
 }
Example #3
0
        //Write to payer/payee xml file
        public void WritePayerPayeeXML()
        {
            using (var context = new FinanceEDMContainer())
            {
                List <PayerPayee> records = AllPPRecords();

                String[] columnname = { "PPId", "Name", "Address", "DOB", "Email", "UserDetailsUserId" };


                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;
                XmlWriter writer = XmlWriter.Create("PayerPayee.xml", settings);
                writer.WriteStartDocument();
                writer.WriteStartElement("PayerPayee");

                for (int i = 0; i < records.Count; i++)
                {
                    writer.WriteStartElement("PayersPayees");
                    writer.WriteAttributeString(columnname[0], records[i].GetType().GetProperty(columnname[0]).GetValue(records[i]).ToString());

                    for (int e = 1; e < columnname.Length; e++)
                    {
                        writer.WriteAttributeString(columnname[e], records[i].GetType().GetProperty(columnname[e]).GetValue(records[i]).ToString());
                    }
                    writer.WriteEndElement();
                }

                writer.WriteEndDocument();
                writer.Close();
            }
        }
Example #4
0
 //Get transaction by Date
 public Transaction[] GetTransaction(String Date)
 {
     using (var context = new FinanceEDMContainer())
     {
         return(context.Transactions.Where(e => e.Date == Date).ToArray());
     }
 }
Example #5
0
        //Write all the transactions to the xml file
        public void WriteTransactionXML(String date)
        {
            using (var context = new FinanceEDMContainer())
            {
                Transaction[] records = GetTransaction(date);

                String[] columnname = { "Category", "Description", "Recuring", "Amount", "TransactionType", "PayerPayeePPId", "TransactionId" };


                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;
                XmlWriter writer = XmlWriter.Create(date + ".xml", settings);
                writer.WriteStartDocument();
                writer.WriteStartElement("Transactions");
                writer.WriteAttributeString("Date", date);

                for (int i = 0; i < records.Length; i++)
                {
                    writer.WriteStartElement("Transaction");


                    for (int e = 0; e < columnname.Length; e++)
                    {
                        writer.WriteAttributeString(columnname[e], records[i].GetType().GetProperty(columnname[e]).GetValue(records[i]).ToString());
                    }

                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Close();
            }
        }
Example #6
0
 public Transaction GetTransaction(int Id)
 {
     using (var context = new FinanceEDMContainer())
     {
         Debug.WriteLine(Id);
         return(context.Transactions.Where(e => e.TransactionId == Id).Single());
     }
 }
Example #7
0
 //Remove a payeer or payer from the database based on the id
 public bool RemovePayerPayee(int id)
 {
     using (var context = new FinanceEDMContainer())
     {
         var record = context.PayerPayees.Where(e => e.PPId == id).Single();
         context.PayerPayees.Remove(record);
         context.SaveChanges();
     }
     return(true);
 }
Example #8
0
 //remove a transaction by id
 public bool RemoveTransaction(int id)
 {
     using (var context = new FinanceEDMContainer())
     {
         var remove = context.Transactions.Where(e => e.TransactionId == id).Single();
         context.Transactions.Remove(remove);
         context.SaveChanges();
     }
     return(true);
 }
Example #9
0
 //add a payer or payee to the database
 public bool AddPayerPayee(PayerPayee obj)
 {
     using (var context = new FinanceEDMContainer())
     {
         //obj.UserDetailsUserId = Session.SessionID;
         obj.UserDetailsUserId = 1;
         context.PayerPayees.Add(obj);
         context.SaveChanges();
     }
     return(true);
 }
Example #10
0
 //Add a transaction to the database
 public bool AddTransaction(List <Transaction> obj)
 {
     using (var context = new FinanceEDMContainer())
     {
         foreach (Transaction item in obj)
         {
             context.Transactions.Add(item);
             context.SaveChanges();
         }
     }
     return(true);
 }
Example #11
0
 //update a payer or payee based on the id
 public bool UpdatePayerPayee(PayerPayee obj)
 {
     using (var context = new FinanceEDMContainer())
     {
         var record = context.PayerPayees.SingleOrDefault(e => e.PPId == obj.PPId);
         record.Name    = obj.Name;
         record.Address = obj.Address;
         record.DOB     = obj.DOB;
         record.Email   = obj.Email;
         //obj.UserDetailsUserId = Session.SessionID;
         record.UserDetailsUserId = 1;
         context.SaveChanges();
     }
     return(true);
 }
Example #12
0
 //Authenticate user login
 public bool LoginAuthentication(String email, String password)
 {
     using (var context = new FinanceEDMContainer())
     {
         var userRecord = context.UserDetails.Where(e => e.Email == email && e.Password == password);
         if (userRecord.Any())
         {
             Session.SessionID = userRecord.Single().UserId;
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Example #13
0
 //update the transaction fields
 public bool UpdateTransaction(Transaction obj)
 {
     using (var context = new FinanceEDMContainer())
     {
         var record = context.Transactions.SingleOrDefault(e => e.TransactionId == obj.TransactionId);
         record.Category        = obj.Category;
         record.Date            = obj.Date;
         record.Description     = obj.Description;
         record.PayerPayeePPId  = obj.PayerPayeePPId;
         record.Recuring        = obj.Recuring;
         record.TransactionId   = obj.TransactionId;
         record.TransactionType = obj.TransactionType;
         context.SaveChanges();
     }
     return(true);
 }
Example #14
0
 //register new user
 public bool AddUser(UserDetails obj)
 {
     using (var context = new FinanceEDMContainer())
     {
         var userRecord = context.UserDetails.Where(e => e.Email == obj.Email);
         if (userRecord.Any())
         {
             return(false);
         }
         else
         {
             context.UserDetails.Add(obj);
             context.SaveChanges();
         }
     }
     return(true);
 }
Example #15
0
        public double predict(String Date)
        {
            List <double> day = new List <double>();
            List <double> totalTransaction = new List <double>();

            using (var context = new FinanceEDMContainer())
            {
                List <Transaction> lst = context.Transactions.Where(e => e.TransactionType == "Expense").ToList().OrderBy(e => DateTime.Parse(e.Date)).ToList();
                for (int i = 0; i < (lst.Count - 1); i++)
                {
                    double daydiff = (DateTime.Parse(lst[i + 1].Date) - DateTime.Parse(lst[i].Date)).TotalDays;
                    if (daydiff != 0)
                    {
                        day.Add(daydiff);
                        totalTransaction.Add(lst[i].Amount);
                    }
                    else
                    {
                        totalTransaction[totalTransaction.Count - 1] = (lst[i].Amount + lst[i + 1].Amount);
                    }
                }
                Debug.WriteLine("Day c" + day.Count);
                foreach (double d in day)
                {
                    Debug.WriteLine(d);
                }
                Debug.WriteLine("Trans c" + totalTransaction.Count);
                foreach (double t in totalTransaction)
                {
                    Debug.WriteLine(t);
                }

                //y = a +bx
                //a= (sum(amount)*(sum(day^2))) - (sum(day) * sum(amount *days)) /  lst.count * (sum(day^2)) - sum(amount)*(sum(day^2)
                //b = lst.count * (sum(amount*days)) - sum(day) *sum(amount)  / lst.count *sum(day^2) - sum(day) ^2

                double amountsqtotal = 0;
                double amounttotal   = 0;

                foreach (double t in totalTransaction)
                {
                    amounttotal   += t;
                    amountsqtotal += Math.Pow(t, 2);
                }

                double daysqtotal = 0;
                double daytotal   = 0;
                foreach (double d in day)
                {
                    daytotal   += d;
                    daysqtotal += Math.Pow(d, 2);
                }

                double xytotal = 0;
                for (int i = 0; i < day.Count; i++)
                {
                    xytotal += day[i] * totalTransaction[i];
                }
                double a = ((amounttotal * daysqtotal) - (daytotal * xytotal)) / ((day.Count * daysqtotal) - (amounttotal * Math.Pow(daytotal, 2)));
                double b = ((day.Count * xytotal) - (daytotal * amounttotal)) / ((day.Count * daysqtotal) - Math.Pow(daytotal, 2));

                Debug.WriteLine(a + " " + b);

                double y = a + b * (DateTime.Parse(Date) - DateTime.Parse(lst[lst.Count - 1].Date)).TotalDays;

                Debug.WriteLine(y);
                return(y);
            }
        }