public async Task Send(int creditorId) { bool actuallySend = false; Console.Write("Type 'true' to actually send emails: "); bool.TryParse(Console.ReadLine(), out actuallySend); var person = mDb.Person .Where(p => p.Id == creditorId) .Include(p => p.PaymentIdentity).ThenInclude(p => p.PaymentMeth) .Single(); var transactions = mDb.Transaction .Where(t => t.CreditorId != t.DebtorId && (t.CreditorId == person.Id || t.DebtorId == person.Id) && (!t.Creditor.IsDeleted && !t.Debtor.IsDeleted)); foreach (var dontUse in PEOPLE_TO_EXCLUDE) { var p = dontUse; transactions = transactions.Where(t => t.DebtorId != p && t.CreditorId != p); } var netMoney = DebtGraph.CalculateDebts(mDb, transactions, true, TextWriter.Null); var swGraph = new StringWriter(); DebtGraph.WriteGraph(netMoney, swGraph); var bytes = DebtGraph.RenderGraphAsPng(swGraph.ToString()); var debtors = DebtGraph.GreatestDebtor(netMoney); var myDebt = debtors.Where(d => d.Item1.Id == person.Id).SingleOrDefault(); if (myDebt != null) { debtors.Remove(myDebt); } debtors = debtors.Where(tup => tup.Item2 > 1000 && !string.IsNullOrEmpty(tup.Item1.Email)).ToList(); int sentSoFar = 0; foreach (var tup in debtors) { var fields = ProcessOnePerson(person, tup.Item1, tup.Item2); if (actuallySend) { await mEmail.SendHtmlEmailAsync(tup.Item1.FullName, tup.Item1.Email, "DKP Invoice", fields.BODY); } Console.WriteLine(actuallySend ? "Sent {0,2}/{1,2} ({2} {3})" : "Would send: {2} {3}", ++sentSoFar, debtors.Count, tup.Item1.FirstName, tup.Item1.LastName); } Console.WriteLine(); Console.WriteLine("Done! Press enter to exit."); Console.ReadLine(); }
public ActionResult Display(int[] peopleIds) { var people = peopleIds .Select(i => dc.Person.Where(p => p.Id == i).Single()) .ToArray(); var swLog = new StringWriter(); var netMoney = DebtGraph.CalculateDebts(dc, people, true, swLog); var swGraph = new StringWriter(); DebtGraph.WriteGraph(netMoney, swGraph); var svg = DebtGraph.RenderGraphAsSvg(swGraph.ToString()); var mod = new AnalyseModel(); mod.LogOutput = swLog.ToString(); mod.ImageSvg = svg; mod.Debtors = DebtGraph.GreatestDebtor(netMoney); return(View(mod)); }
// // GET: /MyDebt/Details/5 public ActionResult Details(int id) { var person = mData.Person.Where(p => p.Id == id).Single(); var transactions = mData.Transaction.Include(t => t.Creditor).Include(t => t.Debtor) .Where(t => t.CreditorId != t.DebtorId && !t.Creditor.IsDeleted && !t.Debtor.IsDeleted && (t.CreditorId == person.Id || t.DebtorId == person.Id)) .ToList(); var netMoney = DebtGraph.CalculateDebts(mData, transactions, true, TextWriter.Null); var swGraph = new StringWriter(); DebtGraph.WriteGraph(netMoney, swGraph); var svg = DebtGraph.RenderGraphAsSvg(swGraph.ToString()); var creditors = DebtGraph.GreatestDebtor(netMoney); var myDebt = creditors.Where(d => d.Item1.Id == person.Id).SingleOrDefault(); if (myDebt != null) { creditors.Remove(myDebt); } //change the list of debtors in to creditors creditors = creditors.Select(c => new Tuple <Person, int>(c.Item1, -c.Item2)) .Reverse() .ToList(); var mod = new MyDebtModel(); mod.Person = person; mod.ImageSvg = svg; mod.Creditors = creditors; mod.OverallDebt = (myDebt == null) ? 0 : myDebt.Item2; return(View(mod)); }