コード例 #1
0
ファイル: Bill.cs プロジェクト: chase-peta/MyFinances-Old
        public static Bill GetBill(this LinkToDBDataContext context, int id)
        {
            Bill bill = context.Bills.FirstOrDefault(x => x.Id == id).LoadBill();

            if (bill.BillHistories.Any())
            {
                List <BillHistoryAverage> avgList = new List <BillHistoryAverage>();
                for (int i = 1; i <= 12; i++)
                {
                    IEnumerable <BillHistory> perMonth = bill.BillHistory.Where(x => x.DatePaid.Month == i);
                    if (perMonth.Any())
                    {
                        BillHistoryAverage bha = new BillHistoryAverage(
                            new DateTime((i < bill.DueDate.Month) ? bill.DueDate.Year + 1 : bill.DueDate.Year, i, 1),
                            perMonth.Average(x => x.Amount),
                            perMonth.Min(x => x.Amount),
                            perMonth.Max(x => x.Amount),
                            perMonth.Average(x => x.DatePaid.Day)
                            );
                        avgList.Add(bha);
                    }
                }
                bill.BillHistoryAverage = avgList.OrderBy(x => x.Month);
            }
            return(bill);
        }
コード例 #2
0
        public ActionResult EditPayment(LoanHistory collection)
        {
            ViewBag.Action = "Edit Payment";
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                LoanHistory history = context.GetLoanHistoryItem(collection.Id);
                try
                {
                    history.ModifyDate    = DateTime.Now;
                    history.Version      += 1;
                    history.DatePaid      = collection.DatePaid;
                    history.BasicPayment  = collection.BasicPayment;
                    history.AddPayment    = collection.AddPayment;
                    history.Interest      = collection.Interest;
                    history.Escrow        = collection.Escrow;
                    history.PaymentTypeId = collection.PaymentTypeId;

                    context.SubmitChanges();

                    return(RedirectToAction("View", new { id = history.LoanId }));
                }
                catch
                {
                    return(View("Payment", collection));
                }
            }
        }
コード例 #3
0
 public ActionResult View(int id)
 {
     using (LinkToDBDataContext context = new LinkToDBDataContext())
     {
         return(View(context.GetLoan(id)));
     }
 }
コード例 #4
0
 /* =========================
  * Loan Functions
  * ========================= */
 public ActionResult Index()
 {
     using (LinkToDBDataContext context = new LinkToDBDataContext())
     {
         return(View(context.GetLoans().OrderBy(x => x.DueDate)));
     }
 }
コード例 #5
0
        public ActionResult Edit(int id, Bill collection)
        {
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                Bill bill = context.GetBill(id);

                try
                {
                    bill.ModifyDate = DateTime.Now;
                    bill.Version += 1;
                    bill.Name = collection.Name;
                    bill.Payee = collection.Payee;
                    bill.DueDate = collection.DueDate;
                    bill.Amount = collection.Amount;
                    bill.StaysSame = collection.StaysSame;
                    bill.Shared = collection.Shared;

                    context.SubmitChanges();

                    return RedirectToAction("Index");
                }
                catch
                {
                    ViewBag.Action = "Edit";
                    return View("View", bill);
                }
            }
        }
コード例 #6
0
        public ActionResult Add(Bill collection)
        {
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                try
                {
                    Bill bill = new Bill();
                    bill.CreationDate = DateTime.Now;
                    bill.ModifyDate = DateTime.Now;
                    bill.Version = 1;
                    bill.UserId = 1;
                    bill.PaymentTypeId = 4;
                    bill.IsActive = true;

                    bill.Amount = collection.Amount;
                    bill.DueDate = collection.DueDate;
                    bill.Name = collection.Name;
                    bill.Payee = collection.Payee;
                    bill.Shared = collection.Shared;
                    bill.StaysSame = collection.StaysSame;

                    context.Bills.InsertOnSubmit(bill);
                    context.SubmitChanges();
                    
                    return RedirectToAction("Index");
                }
                catch
                {
                    ViewBag.Action = "Add";
                    return View("View", collection);
                }
            }
        }
コード例 #7
0
 public ActionResult Add()
 {
     using (LinkToDBDataContext context = new LinkToDBDataContext())
     {
         ViewBag.Action = "Add";
         return View("View");
     }
 }
コード例 #8
0
 /* =========================
  * Bill Functions
  * ========================= */
 public ActionResult Index(bool showInactive = false)
 {
     ViewBag.ShowInactive = showInactive;
     using (LinkToDBDataContext context = new LinkToDBDataContext())
     {
         return View(context.GetBills(!showInactive).OrderBy(x => x.DueDate));
     }
 }
コード例 #9
0
 public ActionResult Edit(int id)
 {
     ViewBag.Action = "Edit";
     using (LinkToDBDataContext context = new LinkToDBDataContext())
     {
         return(View("View", context.GetLoan(id)));
     }
 }
コード例 #10
0
 public ActionResult Edit(int id)
 {
     using (LinkToDBDataContext context = new LinkToDBDataContext())
     {
         ViewBag.Action = "Edit";
         return View("View", context.GetBill(id));
     }
 }
コード例 #11
0
 /* =========================
  * Loan History Functions
  * ========================= */
 public ActionResult AddPayment(int id)
 {
     ViewBag.Action = "Add Payment";
     using (LinkToDBDataContext context = new LinkToDBDataContext())
     {
         return(View("Payment", context.GetLoan(id).NextPayment));
     }
 }
コード例 #12
0
ファイル: Bill.cs プロジェクト: chase-peta/MyFinances-Old
        public static IEnumerable <Bill> GetBills(this LinkToDBDataContext context, bool checkIsActive = true)
        {
            IEnumerable <Bill> bills = (checkIsActive) ? context.Bills.Where(x => x.IsActive == true).OrderBy(x => x.DueDate).ToList() : context.Bills.OrderBy(x => x.DueDate).ToList();

            foreach (Bill bill in bills)
            {
                bill.LoadBill();
            }
            return(bills);
        }
コード例 #13
0
ファイル: Loan.cs プロジェクト: chase-peta/MyFinances-Old
        public static IEnumerable <Loan> GetLoans(this LinkToDBDataContext context, bool checkIsActive = true)
        {
            IEnumerable <Loan> loans = (checkIsActive) ? context.Loans.Where(x => x.IsActive == true).ToList() : context.Loans.ToList();

            foreach (Loan loan in loans)
            {
                loan.LoadLoan();
            }
            return(loans);
        }
コード例 #14
0
 public ActionResult EditPayment(int id)
 {
     ViewBag.Action = "Edit Payment";
     using (LinkToDBDataContext context = new LinkToDBDataContext())
     {
         LoanHistory history = context.GetLoanHistoryItem(id);
         history.Loan = context.GetLoan(history.LoanId);
         return(View("Payment", history));
     }
 }
コード例 #15
0
        public ActionResult RenderMenu()
        {
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                ViewBag.bills = context.GetBillsForMenu();
                ViewBag.loans = context.GetLoansForMenu();

                return(PartialView("Menu"));
            }
        }
コード例 #16
0
 public ActionResult EditPayment(int id)
 {
     using (LinkToDBDataContext context = new LinkToDBDataContext())
     {
         BillHistory history = context.GetBillHistoryItem(id);
         history.Bill = context.GetBill(history.BillId);
         ViewBag.Action = "Edit";
         return View("Payment", history);
     }
 }
コード例 #17
0
 public static IEnumerable <BillHistory> GetAllBillHistory(this LinkToDBDataContext context, int year = 0)
 {
     if (year > 0)
     {
         return(context.BillHistories.Where(x => x.DatePaid.Year == year).OrderBy(x => x.DatePaid).ToList());
     }
     else
     {
         return(context.BillHistories.OrderBy(x => x.DatePaid).ToList());
     }
 }
コード例 #18
0
        public ActionResult AddPayment(BillHistory collection)
        {
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                ViewBag.Action = "Add";
                try
                {
                    BillHistory history = new BillHistory();
                    history.CreationDate = DateTime.Now;
                    history.ModifyDate = DateTime.Now;
                    history.Version = 1;
                    history.BillId = collection.Id;

                    Bill bill = context.GetBill(history.BillId);
                    history.Bill = bill;

                    history.Amount = collection.Amount;
                    history.DatePaid = collection.DatePaid;
                    history.Payee = collection.Payee;
                    history.PaymentTypeId = collection.PaymentTypeId;
                    
                    bill.BillHistories.Add(history);

                    if (bill.StaysSame || bill.BillHistoryAverage == null)
                    {
                        bill.DueDate = bill.DueDate.AddMonths(1);
                    }
                    else
                    {
                        IEnumerable<BillHistoryAverage> bha = bill.BillHistoryAverage.Where(x => x.Month.Month == bill.DueDate.AddMonths(1).Month);
                        if (bha.Any())
                        {
                            bill.DueDate = bha.FirstOrDefault().Month;
                            bill.Amount = bha.FirstOrDefault().Average;
                        }
                        else
                        {
                            bill.DueDate = bill.DueDate.AddMonths(1);
                        }
                    }

                    context.SubmitChanges();

                    return RedirectToAction("View", new { id = history.BillId });
                }
                catch
                {
                    return View("Payment", collection);
                }
            }
        }
コード例 #19
0
        public ActionResult Add(Loan collection, string button)
        {
            ViewBag.Action = "Add";
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                Loan loan = new Loan();

                try
                {
                    loan.CreationDate  = DateTime.Now;
                    loan.ModifyDate    = DateTime.Now;
                    loan.Version       = 1;
                    loan.UserId        = 1;
                    loan.PaymentTypeId = 4;
                    loan.IsActive      = true;

                    loan.Name                = collection.Name;
                    loan.FirstPaymentDate    = collection.FirstPaymentDate;
                    loan.LoanAmount          = collection.LoanAmount;
                    loan.InterestRate        = collection.InterestRate;
                    loan.PaymentInterestRate = collection.PaymentInterestRate;
                    loan.Term                = collection.Term;
                    loan.AddPayment          = collection.AddPayment;
                    loan.Escrow              = collection.Escrow;
                    loan.InterestCompDaily   = false;
                    loan.InterestCompMonthly = true;

                    context.Loans.InsertOnSubmit(loan);

                    switch (button)
                    {
                    case "Calculate":
                        loan = loan.LoadLoan();
                        ViewBag.Calculate = true;
                        return(View("View", loan));

                    case "Save":
                        context.SubmitChanges();
                        return(RedirectToAction("Index"));

                    default:
                        return(View("View", loan));
                    }
                }
                catch
                {
                    return(View("View", loan));
                }
            }
        }
コード例 #20
0
        public ActionResult Index(int year = 0)
        {
            year = (year == 0) ? DateTime.Now.Year : year;
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                IEnumerable <BillHistory> billHistories = context.GetAllBillHistory(year);
                IEnumerable <LoanHistory> loanHistories = context.GetAllLoanHistory(year);

                DateTime billStartDate = billHistories.Min(x => x.DatePaid);
                DateTime loanStartDate = loanHistories.Min(x => x.DatePaid);
                int      startMonth    = (billStartDate < loanStartDate) ? billStartDate.Month : loanStartDate.Month;

                DateTime billEndDate = billHistories.Max(x => x.DatePaid);
                DateTime loanEndDate = loanHistories.Max(x => x.DatePaid);
                int      endMonth    = (billEndDate > loanEndDate) ? billEndDate.Month : loanEndDate.Month;

                List <DashboardDateRange> dateRanges = new List <DashboardDateRange>();
                for (var month = startMonth; month <= endMonth; month++)
                {
                    dateRanges.Add(new DashboardDateRange(
                                       new DateTime(year, month, 1),
                                       new DateTime(year, month, DateTime.DaysInMonth(year, month))
                                       ));
                }

                foreach (DashboardDateRange range in dateRanges)
                {
                    range.Items = billHistories.Where(x => x.DatePaid >= range.StartDate && x.DatePaid <= range.EndDate).Select(x => new DashboardItem(x)).ToList();
                    range.Items = range.Items.Concat(loanHistories.Where(x => x.DatePaid >= range.StartDate && x.DatePaid <= range.EndDate).Select(x => new DashboardItem(x)).ToList());
                    range.Items = range.Items.OrderBy(x => x.Date);
                }

                DashboardViewModel viewModel = new DashboardViewModel();
                viewModel.DateRanges  = dateRanges.OrderBy(x => x.StartDate).Reverse();
                viewModel.CurrentYear = year;

                int yearBill = context.BillHistories.Max(x => x.DatePaid).Year;
                int yearLoan = context.LoanHistories.Max(x => x.DatePaid).Year;
                viewModel.EndYear = (yearBill > yearLoan) ? yearBill : yearLoan;

                yearBill            = context.BillHistories.Min(x => x.DatePaid).Year;
                yearLoan            = context.LoanHistories.Min(x => x.DatePaid).Year;
                viewModel.StartYear = (yearBill < yearLoan) ? yearBill : yearLoan;

                return(View(viewModel));
            }
        }
コード例 #21
0
        /* =========================
         * Bill History Functions
         * ========================= */
        public ActionResult AddPayment(int id)
        {
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                Bill bill = context.GetBill(id);

                BillHistory history = new BillHistory();
                history.Amount = bill.Amount;
                history.DatePaid = bill.DueDate;
                history.Payee = bill.Payee;
                history.PaymentTypeId = bill.PaymentTypeId;
                history.Bill = bill;
                ViewBag.Action = "Add";

                return View("Payment", history);
            }
        }
コード例 #22
0
        public ActionResult Edit(int id, Loan collection, string button)
        {
            ViewBag.Action = "Edit";
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                Loan loan = context.GetLoan(id);

                try
                {
                    loan.ModifyDate          = DateTime.Now;
                    loan.Version            += 1;
                    loan.Name                = collection.Name;
                    loan.FirstPaymentDate    = collection.FirstPaymentDate;
                    loan.LoanAmount          = collection.LoanAmount;
                    loan.InterestRate        = collection.InterestRate;
                    loan.PaymentInterestRate = collection.PaymentInterestRate;
                    loan.Term                = collection.Term;
                    loan.AddPayment          = collection.AddPayment;
                    loan.Escrow              = collection.Escrow;

                    switch (button)
                    {
                    case "Calculate":
                        loan = loan.LoadLoan();
                        ViewBag.Calculate = true;
                        ViewBag.Action    = "Edit";
                        return(View("View", loan));

                    case "Save":
                        context.SubmitChanges();
                        return(RedirectToAction("Index"));

                    default:
                        ViewBag.Action = "Edit";
                        return(View("View", loan));
                    }
                }
                catch
                {
                    return(View("View", loan));
                }
            }
        }
コード例 #23
0
        public ActionResult Paid (int id)
        {
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                BillHistory history = new BillHistory();
                history.CreationDate = DateTime.Now;
                history.ModifyDate = DateTime.Now;
                history.Version = 1;
                history.BillId = id;

                Bill bill = context.GetBill(id);

                history.Amount = bill.Amount;
                history.DatePaid = bill.DueDate;
                history.Payee = bill.Payee;
                history.PaymentTypeId = bill.PaymentTypeId;
                history.Bill = bill;

                if (bill.StaysSame || bill.BillHistoryAverage == null)
                {
                    bill.DueDate = bill.DueDate.AddMonths(1);
                }
                else
                {
                    DateTime useDate = bill.DueDate;
                    IEnumerable<BillHistoryAverage> bha = bill.BillHistoryAverage.Where(x => x.Month.Month == useDate.AddMonths(1).Month);
                    if (bha.Any())
                    {
                        bill.DueDate = bha.FirstOrDefault().Month;
                        bill.Amount = bha.FirstOrDefault().Average;
                    }
                    else
                    {
                        bill.DueDate = bill.DueDate.AddMonths(1);
                    }
                }

                context.SubmitChanges();
                return RedirectToAction("Index", "Home", null);
            }
        }
コード例 #24
0
        public ActionResult EditPayment(BillHistory collection)
        {
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                BillHistory history = context.GetBillHistoryItem(collection.Id);
                ViewBag.Action = "Edit";
                try
                {
                    history.ModifyDate = DateTime.Now;
                    history.Version += 1;
                    history.DatePaid = collection.DatePaid;
                    history.Amount = collection.Amount;
                    history.Payee = collection.Payee;
                    
                    context.SubmitChanges();

                    return RedirectToAction("View", new { id = history.BillId });
                }
                catch
                {
                    return View("Payment", history);
                }
            }
        }
コード例 #25
0
        public ActionResult Index()
        {
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                DashboardViewModel viewModel = new DashboardViewModel();
                IEnumerable <Bill> bills     = context.GetBills();
                IEnumerable <Loan> loans     = context.GetLoans();

                DateTime startDate = DateTime.Now;
                foreach (Bill bill in bills)
                {
                    startDate = (bill.DueDate <= startDate) ? bill.DueDate : startDate;
                }
                foreach (Loan loan in loans)
                {
                    startDate = (loan.DueDate <= startDate) ? loan.DueDate : startDate;
                }
                if (startDate.Day > 1)
                {
                    //startDate = startDate.AddMonths(-1);
                    startDate = new DateTime(startDate.Year, startDate.Month, 1);
                }

                viewModel.DateRanges = InitiateDateRanges(startDate);

                foreach (DashboardDateRange range in viewModel.DateRanges)
                {
                    List <DashboardItem> items = new List <DashboardItem>();

                    foreach (Bill bill in bills)
                    {
                        if (bill.DueDate >= range.StartDate && bill.DueDate <= range.EndDate)
                        {
                            items.Add(new DashboardItem(bill));
                        }
                        if (bill.StaysSame || !bill.BillHistories.Any())
                        {
                            for (int i = 1; i <= 3; i++)
                            {
                                DateTime date = bill.DueDate.AddMonths(i);
                                if (date >= range.StartDate && date <= range.EndDate)
                                {
                                    DashboardItem item = new DashboardItem(bill);
                                    item.Date = date;
                                    items.Add(item);
                                }
                            }
                        }
                        else
                        {
                            Bill difBill = context.GetBill(bill.Id);
                            foreach (BillHistoryAverage bha in difBill.BillHistoryAverage)
                            {
                                if (bha.Month >= range.StartDate && bha.Month <= range.EndDate && bha.Month.Month != bill.DueDate.Month)
                                {
                                    DashboardItem item = new DashboardItem(bha);
                                    item.Id   = bill.Id;
                                    item.Name = bill.Name;
                                    items.Add(item);
                                }
                            }
                        }

                        if (bill.BillHistories.Any())
                        {
                            foreach (BillHistory history in bill.BillHistory)
                            {
                                if (history.DatePaid >= range.StartDate && history.DatePaid <= range.EndDate)
                                {
                                    items.Add(new DashboardItem(history));
                                }
                            }
                        }
                    }

                    foreach (Loan loan in loans)
                    {
                        foreach (LoanOutlook outlook in loan.LoanOutlook)
                        {
                            if (outlook.Date >= range.StartDate && outlook.Date <= range.EndDate)
                            {
                                DashboardItem dbItem = new DashboardItem(outlook);
                                dbItem.Name = loan.Name;
                                dbItem.Id   = loan.Id;
                                items.Add(dbItem);
                            }
                        }
                        foreach (LoanHistory history in loan.LoanHistory)
                        {
                            if (history.DatePaid >= range.StartDate && history.DatePaid <= range.EndDate)
                            {
                                items.Add(new DashboardItem(history));
                            }
                        }
                    }

                    range.Items = items.OrderBy(x => x.Date);
                }

                return(View(viewModel));
            }
        }
コード例 #26
0
ファイル: Loan.cs プロジェクト: chase-peta/MyFinances-Old
        public static Loan GetLoan(this LinkToDBDataContext context, int id)
        {
            Loan loan = context.Loans.FirstOrDefault(x => x.Id == id).LoadLoan();

            return(loan);
        }
コード例 #27
0
ファイル: Loan.cs プロジェクト: chase-peta/MyFinances-Old
 public static IEnumerable <Loan> GetLoansForMenu(this LinkToDBDataContext context)
 {
     return(context.Loans.Where(x => x.IsActive == true).OrderBy(x => x.Name).ToList());
 }
コード例 #28
0
 public static BillHistory GetBillHistoryItem(this LinkToDBDataContext context, int id)
 {
     return(context.BillHistories.FirstOrDefault(x => x.Id == id));
 }