Example #1
0
        public ActionResult CreateDebt(DebtModel model)
        {
            var debtOwner = (from p in NhSession.Query<Tenant>() where p.Name == CurrentUser.Name select p).First();
            var debtors = (from p in NhSession.Query<Tenant>() where p.Id != debtOwner.Id && p.Instance == debtOwner.Instance  && !p.Archived select p);

            foreach (var debtor in debtors)
            {
                var debt = new Debt
                {
                    Amount = model.Amount / (debtors.Count() + 1),
                    Description = model.Description,
                    Debtor = debtor,
                    Paid = false,
                    Person = debtOwner,
                    CreatedDate = DateTime.Now
                };

                NhSession.Save(debt);
                NhSession.Save(debtor);
            }

            return RedirectToAction("Index");
        }
Example #2
0
        public ActionResult CreateDebtForOnePerson(DebtModel model)
        {
            var debtor = (from p in NhSession.Query<Tenant>() where p.Id == model.PersonId select p).First();

            var debt = new Debt
                       {
                           Amount = model.Amount,
                           CreatedDate = DateTime.Now,
                           Debtor = debtor,
                           Description = model.Description,
                           Person = CurrentUser,
                           Paid = false
                       };

            NhSession.Save(debt);

            return RedirectToAction("Index");
        }