public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     if (WebHelpers.GetSession().IsNull())
     {
         filterContext.Result = new RedirectResult("/");
     }
 }
示例#2
0
        private SettingsViewModel GetViewModel()
        {
            var userObj = Repository.GetById(WebHelpers.GetSession().UserId);

            return(new SettingsViewModel
            {
                Id = userObj.Id,
                Username = userObj.Username,
                UsersList = Repository.GetAll()
            });
        }
示例#3
0
        public ActionResult AddBillToMonth(int monthId, int billId)
        {
            var dbObj = Repository.Context.Bills.Find(billId);

            Repository.Context.Months_Bills.Add(new Months_Bills
            {
                Bill_Id     = dbObj.Id.IsNotNull(out int result) ? result : 0,
                User_Id     = WebHelpers.GetSession().UserId,
                Month_Id    = monthId,
                Description = dbObj.Description,
                Value       = dbObj.Value.ToString().MoneyToDecimal()
            });
示例#4
0
        private ActionResult AddSavings(SavingsFormViewModel viewModelObj)
        {
            BaseRepository.Insert(new Models.DataBase.Savings
            {
                User_Id          = WebHelpers.GetSession().UserId,
                Description      = viewModelObj.Description,
                DateCreated      = DateTime.Now,
                LastModifiedDate = DateTime.Now
            });

            return(Redirect("Savings"));
        }
示例#5
0
        private ActionResult AddBill(BillFormViewModel billViewModel)
        {
            var billObj = new Models.DataBase.Bills
            {
                User_Id     = WebHelpers.GetSession().UserId,
                Description = billViewModel.Description,
                Value       = billViewModel.Value.MoneyToDecimal(),
                Status      = "A"
            };

            Repository.Insert(billObj);

            return(Redirect("Bills"));
        }
示例#6
0
        private ActionResult AddIncome(IncomeFormViewModel incomeViewModel)
        {
            var incomeObj = new Models.DataBase.Incomes
            {
                User_Id     = WebHelpers.GetSession().UserId,
                Description = incomeViewModel.Description,
                Value       = incomeViewModel.Value.MoneyToDecimal(),
                Status      = "A"
            };

            Repository.Insert(incomeObj);

            return(Redirect("Incomes"));
        }
        private HomeViewModel GetViewModel()
        {
            var sessionObj = WebHelpers.GetSession();

            var billsPaid   = Context.Months_Bills.Where(i => i.User_Id == sessionObj.UserId).ToList();
            var incomesPaid = Context.Months_Incomes.Where(i => i.User_Id == sessionObj.UserId).ToList();

            return(new HomeViewModel
            {
                BillsCount = billsPaid.Count() > 0 ? billsPaid.Count(i => i.User_Id == sessionObj.UserId) : 0,
                IncomesCount = billsPaid.Count() > 0 ? billsPaid.Count(i => i.User_Id == sessionObj.UserId) : 0,
                TotalBillsPaid = billsPaid.Count() > 0 ? billsPaid.Max(i => i.Value).ToString("C3") : "0",
                TotalIncomesPaid = incomesPaid.Count() > 0 ? incomesPaid.Max(i => i.Value).ToString("C3") : "0"
            });
        }
示例#8
0
        public ActionResult AddTransaction(SavingsFormViewModel savingsObj)
        {
            BaseRepository.Context.Savings_Transactions.Add(new Savings_Transactions
            {
                Savings_Id      = savingsObj.Id.ToInt(),
                User_Id         = WebHelpers.GetSession().UserId,
                Description     = savingsObj.TransactionForm.Description,
                InputDate       = savingsObj.TransactionForm.InputDate.ToDateTime(),
                TransactionDate = DateTime.Now,
                Type            = savingsObj.TransactionForm.Type,
                Value           = savingsObj.TransactionForm.Value.MoneyToDecimal()
            });

            BaseRepository.Context.SaveChanges();

            CalculateSavings(savingsObj.Id.ToInt());

            return(Redirect($"EditSavings?id={savingsObj.Id}"));
        }
示例#9
0
        private List <SavingsViewModel> GetSavings()
        {
            List <SavingsViewModel> savingsList = new List <SavingsViewModel>();

            var savings = BaseRepository.Context.Savings
                          .Where(i => i.User_Id == WebHelpers.GetSession().UserId).ToList();

            foreach (var saving in savings)
            {
                var lastTransaction = BaseRepository.Context.Savings_Transactions
                                      .Where(i => i.Savings_Id == saving.Id).ToList().LastOrDefault();

                savingsList.Add(new SavingsViewModel
                {
                    Id              = saving.Id.ToString(),
                    Description     = saving.Description,
                    TotalAmount     = saving.TotalAmount.ToString(),
                    LastTransaction = lastTransaction.IsNull() ? "No transaction Found." : $"{lastTransaction.Description} || {lastTransaction.InputDate}"
                });
            }

            return(savingsList);
        }