Exemple #1
0
        public async Task <IActionResult> Add([Bind("Name,Amount,Variable,Amount,WorkHours,Function,Company,StartDate")] IncomesAddVm incomeVm)
        {
            if (ModelState.IsValid)
            {
                string           data        = HttpContext.Session.GetString("User");
                UserSessionModel userSession = JsonConvert.DeserializeObject <UserSessionModel>(data);

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

                Income newIncomes = new Income {
                    FK = fk,

                    Name      = incomeVm.Name,
                    Amount    = incomeVm.Amount,
                    WorkHours = incomeVm.WorkHours,
                    Variable  = incomeVm.Variable,

                    Function  = incomeVm.Function,
                    Company   = incomeVm.Company,
                    StartDate = incomeVm.StartDate
                };

                _context.Add(newIncomes);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(incomeVm));
        }
Exemple #2
0
        public async Task <IActionResult> Add([Bind("Monthly,Type,Description,AccountNumber,StartDate")] SecurityAddVm securityVm)
        {
            if (ModelState.IsValid)
            {
                string           data        = HttpContext.Session.GetString("User");
                UserSessionModel userSession = JsonConvert.DeserializeObject <UserSessionModel>(data);

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

                Security newSecurities = new Security {
                    FK = fk,

                    StartDate = DateTime.Parse(securityVm.StartDate),
                    Monthly   = securityVm.Monthly,
                    Type      = securityVm.Type,

                    Description   = securityVm.Description,
                    AccountNumber = securityVm.AccountNumber,
                };

                _context.Add(newSecurities);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(securityVm));
        }
Exemple #3
0
        public async Task <IActionResult> Add([Bind("Name,Life,Type,Variable,Cost,AccountNumber,Creditor,expenseTypes")] ExpenseAddVm expenseVm)
        {
            if (ModelState.IsValid)
            {
                string           data        = HttpContext.Session.GetString("User");
                UserSessionModel userSession = JsonConvert.DeserializeObject <UserSessionModel>(data);

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

                Expense newExpense = new Expense {
                    FK            = fk,
                    Name          = expenseVm.Name,
                    AccountNumber = expenseVm.AccountNumber,
                    Life          = expenseVm.Life,
                    Type          = expenseVm.Type,
                    Variable      = expenseVm.Variable,
                    Cost          = expenseVm.Cost,
                    Creditor      = expenseVm.Creditor
                };

                _context.Add(newExpense);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(expenseVm));
        }
Exemple #4
0
        public async Task <IActionResult> SignUp([Bind("Id,Name,FirstName,Email,Country,Password,Age,Currency")] User user)
        {
            if (ModelState.IsValid)
            {
                user.Password = GenerateSHA256String(user.Password);

                _context.Add(user);

                TempData["Message"]     = "Account created, you can now login.";
                TempData["MessageType"] = "success";

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Login)));
            }

            TempData["Message"]     = "Register Failed, please try again.";
            TempData["MessageType"] = "alert";

            return(View(user));
        }