public async Task <IActionResult> Register([Bind("Name, Password, ConfirmPassword, Email")] RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email
                };
                IdentityResult result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    string[] defaultCategories = { "Clothing", "Donations", "Eating Out", "Entertainment", "Gifts", "Groceries", "Health", "Home", "Kids", "Income", "Other", "Personal", "Pets", "Transportation", "Utilities", "Vacation" };
                    foreach (var categoryName in defaultCategories)
                    {
                        Category newCategory = new Category(user, categoryName);
                        _db.Categories.Add(newCategory);
                    }
                    string[] defaultFunds = { "General", "Savings" };
                    foreach (var fundName in defaultFunds)
                    {
                        Fund newFund = new Fund(user, fundName);
                        _db.Funds.Add(newFund);
                    }
                    _db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            {
                return(View());
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Create(Transaction transaction)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            transaction.User = currentUser;
            if (transaction.Type == "Withdrawal")
            {
                transaction.Amount = -transaction.Amount;
            }
            var currentFund = _db.Funds.FirstOrDefault(x => x.FundId == transaction.FundId);

            currentFund.AdjustTotal(transaction);
            _db.Entry(currentFund).State = EntityState.Modified;
            _db.Transactions.Add(transaction);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Create([Bind("Name")] CategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
                var currentUser = await _userManager.FindByIdAsync(userId);

                Category newCategory = new Category
                {
                    User = currentUser,
                    Name = model.Name
                };
                _db.Categories.Add(newCategory);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            {
                return(View());
            }
        }
Beispiel #4
0
        public async Task <IActionResult> Create([Bind("Name", "Minimum", "Goal")] FundViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
                var currentUser = await _userManager.FindByIdAsync(userId);

                Fund newFund = new Fund
                {
                    User    = currentUser,
                    Name    = model.Name,
                    Minimum = model.Minimum,
                    Goal    = model.Goal
                };
                _db.Funds.Add(newFund);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            {
                return(View());
            }
        }