Esempio n. 1
0
        public ActionResult CreateDebtForOnePerson()
        {
            var people = from p in NhSession.Query<Tenant>() where p.Name != CurrentUser.Name && p.Instance == CurrentUser.Instance && !p.Archived select p;
            var model = new DebtModel { People = (from person in people select new SelectListItem(){ Text = person.Name, Value = person.Id.ToString()}).ToList() };

            return View(model);
        }
Esempio n. 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");
        }
Esempio n. 3
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");
        }