public ActionResult Details(int?id) { ViewBag.Action = "Details"; IncomeUser incomeUser = GetIncomeUser(id); if (incomeUser == null) { return(HttpNotFound()); } return(View(incomeUser)); }
public ActionResult Create() { ViewBag.Action = "Create"; IncomeUser incomeUser = new IncomeUser() { PaymentFrequency = PaymentFrequency.Monthly, Date = DateTime.Now }; ViewBag.Users = GetAllAvailableUsers(); return(View("Details", incomeUser)); }
public ActionResult Deactivate(int?id) { IncomeUser incomeUser = GetIncomeUser(id); if (incomeUser == null) { return(HttpNotFound()); } incomeUser.IsActive = false; db.Entry(incomeUser).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(string userId, [Bind(Include = "PaymentFrequency,Date")] IncomeUser incomeUser) { ViewBag.Action = "Create"; if (ModelState.IsValid) { incomeUser.User = db.Users.Find(user.Id); incomeUser.PayeeUser = db.Users.Find(userId); db.IncomeUsers.Add(incomeUser); db.SaveChanges(); return(RedirectToAction("Edit", new { id = incomeUser.ID })); } return(View("Details", incomeUser)); }
public ActionResult Activate(int?id) { IncomeUser incomeUser = GetIncomeUser(id); if (incomeUser == null) { return(HttpNotFound()); } incomeUser.IsActive = true; db.Entry(incomeUser).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", new { id = incomeUser.ID })); }
public ActionResult Edit(int?id) { ViewBag.Action = "Edit"; IncomeUser incomeUser = GetIncomeUser(id); if (incomeUser == null) { return(HttpNotFound()); } ViewBag.Bills = db.Bills.Where(x => x.User.Id == user.Id && x.IsActive).OrderBy(x => x.Name).ToList(); ViewBag.Loans = db.Loans.Where(x => x.User.Id == user.Id && x.IsActive).OrderBy(x => x.Name).ToList(); ViewBag.SharedPercentage = Enum.GetValues(typeof(SharedPercentage)); return(View("Details", incomeUser)); }
public ActionResult DeletePayment(int?id) { IncomeUserPayment incomeUserPayment = GetIncomeUserPayment(id); if (incomeUserPayment == null) { return(HttpNotFound()); } IncomeUser incomeUser = incomeUserPayment.IncomeUser; db.IncomeUserPayments.Remove(incomeUserPayment); db.SaveChanges(); return(RedirectToAction("Details", new { id = incomeUser.ID })); }
public ActionResult Delete(int?id) { IncomeUser incomeUser = GetIncomeUser(id); if (incomeUser == null) { return(HttpNotFound()); } if (incomeUser.IncomeUserPayments.Any()) { db.IncomeUserPayments.RemoveRange(incomeUser.IncomeUserPayments); } db.IncomeUsers.Remove(incomeUser); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult AddPayment(int?id) { ViewBag.Action = "Add Payment"; IncomeUser incomeUser = GetIncomeUser(id); if (incomeUser == null) { return(HttpNotFound()); } NotPaidIncomeUserPayemnt np = incomeUser.NotPaidIncomeUserPayments.OrderBy(x => x.Date).FirstOrDefault(); IncomeUserPayment payment = new IncomeUserPayment() { Date = np.Date, Amount = np.Amount, IncomeUser = incomeUser }; return(View("Payment", payment)); }
protected void UpdateIncomeUserLoans(IncomeUser incomeUser, int[] loanIds, string[] sharedPercentLoans) { foreach (int loanId in loanIds) { Loan loan = db.Loans.Where(x => x.ID == loanId).Include(x => x.SharedWith).FirstOrDefault(); if (loan != null) { db.SharedLoan.RemoveRange(loan.SharedWith.Where(x => x.SharedWithUser.Id == incomeUser.PayeeUser.Id)); string percent = GetPercentById(loanId.ToString(), sharedPercentLoans); percent = (percent == "" ? "Half" : percent); db.SharedLoan.Add( new SharedLoan( loan, incomeUser.PayeeUser, (SharedPercentage)Enum.Parse(typeof(SharedPercentage), percent) ) ); } } }
protected void UpdateIncomeUserBills(IncomeUser incomeUser, int[] billIds, string[] sharedPercentBills) { foreach (int billId in billIds) { Bill bill = db.Bills.Where(x => x.ID == billId).Include(x => x.SharedWith).FirstOrDefault(); if (bill != null) { db.SharedBill.RemoveRange(bill.SharedWith.Where(x => x.SharedWithUser.Id == incomeUser.PayeeUser.Id)); string percent = GetPercentById(billId.ToString(), sharedPercentBills); percent = (percent == "" ? "Half" : percent); db.SharedBill.Add( new SharedBill( bill, incomeUser.PayeeUser, (SharedPercentage)Enum.Parse(typeof(SharedPercentage), percent) ) ); } } }
public ActionResult Edit(int[] billId, string[] sharedPercentBill, int[] loanId, string[] sharedPercentLoan, [Bind(Include = "ID,PaymentFrequency,Date")] IncomeUser subIncomeUser) { ViewBag.Action = "Edit"; IncomeUser incomeUser = db.IncomeUsers.Find(subIncomeUser.ID); if (incomeUser == null) { return(HttpNotFound()); } incomeUser = incomeUser.MapSubmit(subIncomeUser); if (ModelState.IsValid) { db.Entry(incomeUser).State = EntityState.Modified; UpdateIncomeUserBills(incomeUser, billId, sharedPercentBill); UpdateIncomeUserLoans(incomeUser, loanId, sharedPercentLoan); db.SaveChanges(); return(RedirectToAction("Details", new { id = incomeUser.ID })); } ViewBag.Bills = db.Bills.Where(x => x.User.Id == user.Id && x.IsActive).OrderBy(x => x.Name).ToList(); ViewBag.Loans = db.Loans.Where(x => x.User.Id == user.Id && x.IsActive).OrderBy(x => x.Name).ToList(); ViewBag.SharedPercentage = Enum.GetValues(typeof(SharedPercentage)); return(View("Details", incomeUser)); }
protected IncomeUser GetIncomeUser(int?id) { IncomeUser incomeUser = db.IncomeUsers.Find(id); if (incomeUser == null) { return(null); } else if (incomeUser.User.Id == user.Id) { incomeUser = incomeUser.Populate(user); incomeUser.Bills = db.SharedBill.Where(x => x.SharedWithUser.Id == incomeUser.PayeeUser.Id && x.Bill.User.Id == user.Id).OrderBy(x => x.Bill.Name).Include(x => x.Bill).ToList(); incomeUser.Loans = db.SharedLoan.Where(x => x.SharedWithUser.Id == incomeUser.PayeeUser.Id && x.Loan.User.Id == user.Id).OrderBy(x => x.Loan.Name).Include(x => x.Loan).ToList(); incomeUser.BillPayments = db.SharedBillPayment.Where(x => x.SharedWithUser.Id == incomeUser.PayeeUser.Id && x.BillPayment.User.Id == user.Id).OrderBy(x => x.BillPayment.Bill.Name).Include(x => x.BillPayment).ToList(); incomeUser.LoanPayments = db.SharedLoanPayment.Where(x => x.SharedWithUser.Id == incomeUser.PayeeUser.Id && x.LoanPayment.User.Id == user.Id).OrderBy(x => x.LoanPayment.Loan.Name).Include(x => x.LoanPayment).ToList(); List <int> bpIds = new List <int>(); List <int> lpIds = new List <int>(); foreach (IncomeUserPayment p in incomeUser.IncomeUserPayments) { p.BillPayments.ForEach(x => bpIds.Add(x.BillPayment.ID)); p.LoanPayments.ForEach(x => lpIds.Add(x.LoanPayment.ID)); } List <SharedBillPayment> bp = incomeUser.BillPayments.Where(x => !bpIds.Contains(x.BillPayment.ID)).ToList(); List <SharedLoanPayment> lp = incomeUser.LoanPayments.Where(x => !lpIds.Contains(x.LoanPayment.ID)).ToList(); if (bp.Any() || lp.Any()) { DateTime minDate = DateTime.Now; DateTime maxDate = DateTime.Now; if (bp.Any()) { DateTime billMinDate = bp.Min(x => x.BillPayment.DatePaid); DateTime billMaxDate = bp.Max(x => x.BillPayment.DatePaid); if (billMinDate < minDate) { minDate = billMinDate; } if (billMaxDate > maxDate) { maxDate = billMaxDate; } } if (lp.Any()) { DateTime loanMinDate = lp.Min(x => x.LoanPayment.DatePaid); DateTime loanMaxDate = lp.Max(x => x.LoanPayment.DatePaid); if (loanMinDate < minDate) { minDate = loanMinDate; } if (loanMaxDate > maxDate) { maxDate = loanMaxDate; } } minDate = new DateTime(minDate.Year, minDate.Month, incomeUser.Date.Day); maxDate = maxDate.AddMonths(1); maxDate = new DateTime(maxDate.Year, maxDate.Month, incomeUser.Date.Day); incomeUser.NotPaidMinYear = minDate.Year; incomeUser.NotPaidMaxYear = maxDate.Year; incomeUser.NotPaidIncomeUserPayments = new List <NotPaidIncomeUserPayemnt>(); while (minDate < maxDate) { incomeUser.NotPaidIncomeUserPayments.Add(new NotPaidIncomeUserPayemnt { Date = minDate, BillPayments = bp.Where(x => x.BillPayment.DatePaid.Year == minDate.Year && x.BillPayment.DatePaid.Month == minDate.Month).ToList(), LoanPayments = lp.Where(x => x.LoanPayment.DatePaid.Year == minDate.Year && x.LoanPayment.DatePaid.Month == minDate.Month).ToList() }); minDate = minDate.AddMonths(1); } } } else { return(null); } return(incomeUser); }