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));
        }
예제 #2
0
        //
        // 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));
        }