Exemplo n.º 1
0
        // GET: Incomes
        public async Task <IActionResult> Index()
        {
            if (IsLoggedIn())
            {
                string           data        = HttpContext.Session.GetString("User");
                UserSessionModel userSession = JsonConvert.DeserializeObject <UserSessionModel>(data);

                var user = await _context.tbl_users.FirstOrDefaultAsync(u => u.Id == userSession.Id);

                int WorkHoursTotal = 0;

                IncomesOverviewVm incomesOverviewVm = new IncomesOverviewVm();
                incomesOverviewVm.Incomes = _context.Entry(user).Collection(u => u.Incomes).Query().AsEnumerable();
                incomesOverviewVm.Total   = incomesOverviewVm.Incomes.Count();

                foreach (var inc in incomesOverviewVm.Incomes)
                {
                    WorkHoursTotal += inc.WorkHours;
                }

                incomesOverviewVm.WorkHours = WorkHoursTotal;
                incomesOverviewVm.Variable  = incomesOverviewVm.Incomes.Where(e => e.Variable).Count();

                return(View(incomesOverviewVm));
            }

            return(RedirectToAction("Login", "User"));
        }
Exemplo n.º 2
0
        // GET: Securities
        public async Task <IActionResult> Index()
        {
            if (IsLoggedIn())
            {
                string           data        = HttpContext.Session.GetString("User");
                UserSessionModel userSession = JsonConvert.DeserializeObject <UserSessionModel>(data);

                var user = await _context.tbl_users.FirstOrDefaultAsync(u => u.Id == userSession.Id);

                decimal TotalSaved   = 0;
                decimal MonthlySaved = 0;

                SecurityOverviewVm securityOverviewVm = new SecurityOverviewVm();
                securityOverviewVm.Securities  = _context.Entry(user).Collection(u => u.Securities).Query().AsEnumerable();
                securityOverviewVm.nSecurities = securityOverviewVm.Securities.Count();

                foreach (var sec in securityOverviewVm.Securities)
                {
                    TotalSaved += sec.Amount;
                }

                securityOverviewVm.Total = TotalSaved;

                foreach (var sec in securityOverviewVm.Securities)
                {
                    TotalSaved += sec.Monthly;
                }

                securityOverviewVm.Monthly = MonthlySaved;

                return(View(securityOverviewVm));
            }

            return(RedirectToAction("Login", "User"));
        }
Exemplo n.º 3
0
        public async Task <User> UpdateUserData(User user)
        {
            user.Total    = 0;
            user.Negative = 0;
            user.Positive = 0;

            // update expenses
            var expenses = _context.Entry(user).Collection(u => u.Expenses).Query().AsEnumerable();

            if (expenses != null)
            {
                foreach (var exp in expenses)
                {
                    user.Negative += exp.Cost;
                }
            }

            // update incomes


            var incomes = _context.Entry(user).Collection(u => u.Incomes).Query().AsEnumerable();

            if (incomes != null)
            {
                foreach (var inc in incomes)
                {
                    user.Positive += inc.Amount;
                }
            }

            user.Total = user.Positive - user.Negative;

            // save changes to db
            _context.Update(user);
            await _context.SaveChangesAsync();

            // return user to display details
            return(user);
        }
Exemplo n.º 4
0
        // GET: Expense
        public async Task <IActionResult> Index()
        {
            if (IsLoggedIn())
            {
                string           data        = HttpContext.Session.GetString("User");
                UserSessionModel userSession = JsonConvert.DeserializeObject <UserSessionModel>(data);

                var user = await _context.tbl_users.FirstOrDefaultAsync(u => u.Id == userSession.Id);

                ExpensesOverviewVm expensesOverviewVm = new ExpensesOverviewVm();
                expensesOverviewVm.Expenses = _context.Entry(user).Collection(u => u.Expenses).Query().AsEnumerable();
                expensesOverviewVm.Total    = expensesOverviewVm.Expenses.Count();
                expensesOverviewVm.Life     = expensesOverviewVm.Expenses.Where(e => e.Life).Count();
                expensesOverviewVm.Variable = expensesOverviewVm.Expenses.Where(e => e.Variable).Count();

                return(View(expensesOverviewVm));
            }

            return(RedirectToAction("Login", "User"));
        }