Example #1
0
        public async Task <IActionResult> Create([Bind("HouseholdId,Expires,EmailTo,Subject,Body")] Invitation invitation)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(User);

                invitation.HouseholdId = (int)user.HouseholdId;
                invitation.IsValid     = true;
                invitation.Code        = Guid.NewGuid();
                invitation.Created     = DateTime.Now;
                _context.Invitation.Add(invitation);
                await _context.SaveChangesAsync();


                var callbackUrl = Url.Action("AcceptInvitation", "Invitations",
                                             new { email = invitation.EmailTo, code = invitation.Code },
                                             protocol: Request.Scheme);



                var emailBody = $"{invitation.Body} <br/><p><h3>Please accept this invitation by <a href = '{HtmlEncoder.Default.Encode(callbackUrl)}'>Click here</a></h3></p>";
                await _emailSender.SendEmailAsync(invitation.EmailTo, invitation.Subject, emailBody);

                //await _context.SaveChangesAsync();
                return(RedirectToAction("Details", "Households", new { id = invitation.HouseholdId }));
            }
            return(RedirectToAction("Details", "Households"));
        }
        public async Task <IActionResult> Create([Bind("Id,HouseholdId,Created,Subject,Body,IsRead")] Notification notification)
        {
            if (ModelState.IsValid)
            {
                _context.Add(notification);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(notification));
        }
        public async Task <IActionResult> Create([Bind("HouseholdId,Name,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Households", new { id = category.HouseholdId }));
            }
            ViewData["HouseholdId"] = new SelectList(_context.Set <Household>(), "Id", "Id", category.HouseholdId);
            return(View(category));
        }
Example #4
0
        public async Task <IActionResult> Create([Bind("Name,CategoryId,Description,TargetAmount")] CategoryItem categoryItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(categoryItem);
                await _context.SaveChangesAsync();

                var category = await _context.Category.Include(c => c.Household).FirstOrDefaultAsync(c => c.Id == categoryItem.CategoryId);

                return(RedirectToAction("Details", "Households", new { id = category.HouseholdId }));
            }
            return(View(categoryItem));
        }
        public async Task <IActionResult> Create([Bind("HouseholdId,Name,Type,StartingBalance")] BankAccount bankAccount)
        {
            if (ModelState.IsValid)
            {
                bankAccount.FPUserId       = _userManager.GetUserId(User);
                bankAccount.CurrentBalance = bankAccount.StartingBalance;
                _context.Add(bankAccount);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Households", new { id = bankAccount.HouseholdId }));
            }
            return(View(bankAccount));
        }
Example #6
0
        public async Task <IActionResult> Create([Bind("CategoryItemId,BankAccountId,Created,Type,Memo,Amount")] Transaction transaction)
        {
            if (ModelState.IsValid)
            {
                transaction.FPUserId = _userManager.GetUserId(User);
                _context.Add(transaction);
                await _context.SaveChangesAsync();

                //1:Decrease the Bank Current Balance
                var account = await _context.BankAccount.FindAsync(transaction.BankAccountId);

                var oldBalance = account.CurrentBalance;

                if (transaction.Type == Enum.TransactionType.Deposit)
                {
                    account.CurrentBalance += transaction.Amount;
                }
                else
                {
                    //Withdrawl
                    account.CurrentBalance -= transaction.Amount;
                    //2:Increase the Actual Amount of the associated Category Item
                    var categoryItem = await _context.CategoryItem.FindAsync(transaction.CategoryItemId);

                    categoryItem.ActualAmount += transaction.Amount;
                }
                await _context.SaveChangesAsync();

                //3:Look for any needed notifications
                if (account.CurrentBalance < 0)
                {
                    TempData["OverDraft"] = "you overdrft your account. FOO";
                }
                await _notificationService.NotifyOverdraftAsync(transaction, account, oldBalance);

                return(RedirectToAction("Details", "Households", new { id = (await _userManager.GetUserAsync(User)).HouseholdId }));
            }
            ViewData["BankAccountId"]  = new SelectList(_context.BankAccount, "Id", "Name", transaction.BankAccountId);
            ViewData["CategoryItemId"] = new SelectList(_context.CategoryItem, "Id", "Name", transaction.CategoryItemId);
            ViewData["FPUserId"]       = new SelectList(_context.Users, "Id", "FullName", transaction.FPUserId);
            return(View(transaction));
        }
Example #7
0
        public async Task <IActionResult> Leave()

        {
            //Determine who I am here....I dont need any additional info
            //Step 1: Get User Record
            var user = await _userManager.GetUserAsync(User);

            var memberCount = _context.Users.Where(u => u.HouseholdId == user.HouseholdId).Count();

            //Determine is I am actually able to leave or do I have to warn the user
            if (User.IsInRole(nameof(PortalRole.HOH)) && memberCount > 1)
            {
                //Load up a nasty gram to display to the HOH
                TempData["Message"] = "You cannot leave the Household untill all the Members have left";
                return(RedirectToAction("Dashboard"));
            }

            //Step 2: Remove the HouseHoldId
            var householdIdMemento = user.HouseholdId;

            user.HouseholdId = null;
            await _context.SaveChangesAsync();

            //Step 3: get the user's role
            var myRole = (await _userManager.GetRolesAsync(user)).FirstOrDefault();

            //Step 4: Remove them from that role
            await _userManager.RemoveFromRoleAsync(user, myRole);

            //Step 5: Refresh user login
            await _signInManager.RefreshSignInAsync(user);

            //Step 6: If there is nobody left in the Household mark it as deleted or delete it
            if (_context.Users.Where(u => u.HouseholdId == householdIdMemento).Count() == 0)
            {
                //Delete the house
                var household = await(_context.Household.FindAsync(householdIdMemento));
                await _context.SaveChangesAsync();

                //What happens to all the children?
            }

            //Step 7: Redirect to the lobby
            return(RedirectToAction("Lobby, Home"));
        }