public ActionResult Leaving() { var userId = User.Identity.GetUserId(); var user = db.Users.Find(userId); var household = db.Households.Find(user.HouseholdId); if (User.IsInRole("User")) { userRolesHelper.RemoveUserFromRole(userId, "User"); user.HouseholdId = null; db.SaveChanges(); } if (userRolesHelper.IsUserInRole(userId, "HoH")) { if (HouseholdHelper.AnyUsersInHousehold(household.Id)) { HouseholdHelper.AssignRandomHoH(household.Id); } userRolesHelper.RemoveUserFromRole(userId, "HoH"); user.HouseholdId = null; db.Households.Remove(household); db.SaveChanges(); } return(RedirectToAction("Index", "Home")); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { filterContext.Controller.TempData.Remove("oopsMsg"); if (userId == null) { filterContext.Controller.TempData.Add("oopsMsg", "You have to be logged in and authorized to continue."); filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Home" }, { "action", "Oops" } }); } var transactionId = Convert.ToInt32(filterContext.ActionParameters.SingleOrDefault(p => p.Key == "id").Value); var transaction = db.Transactions.AsNoTracking().Where(t => t.Id == transactionId).FirstOrDefault(); var transactionUserId = transaction.EnteredById; int?userHouseholdId = db.Users.Find(userId).HouseholdId; if (HouseholdHelper.GetUserHouseholdId(transactionUserId) != userHouseholdId) { filterContext.Controller.TempData.Add("oopsMsg", "You have to be logged in and authorized to view this Household."); filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Home" }, { "action", "Oops" } }); } base.OnActionExecuting(filterContext); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Transaction transaction = db.Transactions.Find(id); if (transaction == null) { return(HttpNotFound()); } var userHousholdId = HouseholdHelper.GetUserHouseholdId(User.Identity.GetUserId()); var enteredById = db.Users.Where(u => u.HouseholdId == userHousholdId); var houseAccountId = db.HouseAccounts.Where(a => a.HouseholdId == userHousholdId); var budgetItems = db.BudgetItems.Where(i => db.Budgets.Any(b => b.Id == i.BudgetId && b.HouseholdId == userHousholdId)); ViewBag.EnteredById = new SelectList(enteredById, "Id", "FirstName", transaction.EnteredById); ViewBag.HouseAccountId = new SelectList(houseAccountId, "Id", "Name", transaction.HouseAccountId); ViewBag.TransactionTypeId = new SelectList(db.TransactionTypes, "Id", "Name", transaction.TransactionTypeId); ViewBag.BudgetItemId = new SelectList(budgetItems, "Id", "Name", transaction.BudgetItemId); return(View(transaction)); }
public async Task <ActionResult> Invitation(string Email) { try { var email = new MailAddress(Email).ToString(); foreach (var invite in db.Invitations.Where(i => i.EmailTo.ToLower() == email.ToLower())) { if (invite.Accepted) { TempData["status"] = "accepted"; return(RedirectToAction("Index", "Households", null)); } if (invite.Expires >= DateTime.Now) { TempData["status"] = "pending"; return(RedirectToAction("Index", "Households", null)); } } Invitation invitation = new Invitation { Created = DateTime.Now, Expires = DateTime.Now.AddDays(3), EmailTo = email, Subject = $"{User.Identity.FullName()} has invited you to join Budget Destoyer", Body = $"{User.Identity.FullName()} has invited you to join their house {HouseholdHelper.GetHouseholdName(User.Identity.GetUserId())} on Budget Destroyer", HouseholdId = Convert.ToInt32(HouseholdHelper.GetUserHouseholdId(User.Identity.GetUserId())), UniqueCode = Guid.NewGuid(), Accepted = false }; db.Invitations.Add(invitation); db.SaveChanges(); string code = invitation.UniqueCode.ToString(); var callbackUrl = Url.Action("RegisterInvitation", "Account", new { code = code }, protocol: Request.Url.Scheme); //var message = "<p>Email From: <bold>{0}</bold>({1})</p><p> Message:</p><p>{2}</p> "; var bodyButton = "<a href =\"" + callbackUrl + "\">here</a>"; var sentEmail = new MailMessage("*****@*****.**", email) { Subject = invitation.Subject, Body = $"{invitation.Body}. Please Join by clicking {bodyButton}", IsBodyHtml = true }; var svc = new PersonalEmail(); await svc.SendAsync(sentEmail); TempData["status"] = "success"; return(RedirectToAction("Index", "Households", null)); } catch (FormatException ex) { TempData["status"] = "error"; return(RedirectToAction("Index", "Households", null)); } }
public BankAccountController() { DbContext = new ApplicationDbContext(); HouseholdHelper = new HouseholdHelper(DbContext); BankAccountHelper = new BankAccountHelper(DbContext); TransactionHelper = new TransactionHelper(DbContext); BankAccountHelper = new BankAccountHelper(DbContext); }
public ActionResult JoinHousehold(int HHId) { HouseholdHelper helper = new HouseholdHelper(); helper.AddUserToHousehold(User.Identity.GetUserId(), HHId); return(RedirectToAction("Details", new { id = HHId })); }
public ActionResult Index() { if (HouseholdHelper.IsUserInAHouse(User.Identity.GetUserId())) { return(RedirectToAction("Index", "Households")); } return(View()); }
public ActionResult Create([Bind(Include = "Id,HouseholdId,Name,Descriptions,Amount")] Budget budget) { if (ModelState.IsValid) { budget.HouseholdId = HouseholdHelper.GetUserHouseholdId(User.Identity.GetUserId()).Value; db.Budgets.Add(budget); db.SaveChanges(); return(RedirectToAction("Index", "Households")); } ViewBag.HouseholdId = new SelectList(db.Households, "Id", "Name", budget.HouseholdId); return(View(budget)); }
public ActionResult Create(string HHName) { Household hh = new Household { Id = 0, Name = HHName }; HouseholdHelper helper = new HouseholdHelper(); helper.AddUserToHousehold(User.Identity.GetUserId(), hh.Id); db.Households.Add(hh); db.SaveChanges(); return(RedirectToAction("Details", new { id = hh.Id })); }
public ActionResult Create([Bind(Include = "Id,Name")] Household household) { if (ModelState.IsValid) { db.Households.Add(household); db.SaveChanges(); HouseholdHelper.AddUserToHouse(User.Identity.GetUserId(), household.Id); userRolesHelper.AddUserToRole(User.Identity.GetUserId(), "HoH"); return(RedirectToAction("Index")); } return(View(household)); }
public ActionResult Create([Bind(Include = "Id,HouseholdId,Name,Balance,ReconciledBalace")] HouseAccount houseAccount) { if (ModelState.IsValid) { houseAccount.HouseholdId = HouseholdHelper.GetUserHouseholdId(User.Identity.GetUserId()).Value; houseAccount.ReconciledBalace = 0.00M; db.HouseAccounts.Add(houseAccount); db.SaveChanges(); return(RedirectToAction("Index", "Households")); } ViewBag.HouseholdId = new SelectList(db.Households, "Id", "Name", houseAccount.HouseholdId); return(View(houseAccount)); }
// GET: Households public ActionResult Index() { var householdId = HouseholdHelper.GetUserHouseholdId(User.Identity.GetUserId()); ViewBag.HouseAccounts = db.HouseAccounts.Where(h => h.HouseholdId == householdId).ToList(); ViewBag.Transactions = db.Transactions.Where(t => db.HouseAccounts.Any(h => h.Id == t.HouseAccountId && h.HouseholdId == householdId)).ToList(); ViewBag.HouseAccountsSelect = new SelectList(ViewBag.HouseAccounts, "Id", "Name"); ViewBag.TransactionTypes = new SelectList(db.TransactionTypes, "Id", "Name"); ViewBag.BudgetItems = db.BudgetItems.Where(i => db.Budgets.Any(b => b.Id == i.BudgetId && b.HouseholdId == householdId)).ToList(); ViewBag.BudgetItemSelect = new SelectList(ViewBag.BudgetItems, "Id", "Name"); ViewBag.Budgets = db.Budgets.Where(b => b.HouseholdId == householdId).ToList(); ViewBag.BudgetId = new SelectList(ViewBag.Budgets, "Id", "Name"); return(View(db.Households.Find(householdId))); }
public HouseholdController() { DbContext = new ApplicationDbContext(); HouseholdHelper = new HouseholdHelper(DbContext); UserHelper = new UserHelper(DbContext); }
protected override void Seed(FinancialPortal.Models.ApplicationDbContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. var houseHelper = new HouseholdHelper(); // Instance of RoleManager var roleManager = new RoleManager <IdentityRole>( new RoleStore <IdentityRole>(context)); //Instance of UserManager var userManager = new UserManager <ApplicationUser>( new UserStore <ApplicationUser>(context)); // Roles #region Seeded Roles if (!context.Roles.Any(r => r.Name == "Admin")) { roleManager.Create(new IdentityRole { Name = "Admin" }); } if (!context.Roles.Any(r => r.Name == "HouseholdMember")) { roleManager.Create(new IdentityRole { Name = "HouseholdMember" }); } if (!context.Roles.Any(r => r.Name == "NoHousehold")) { roleManager.Create(new IdentityRole { Name = "NoHousehold" }); } #endregion //List of Users (comment) #region User Index //Avengers Users Seed //----------------------- //Derrick (Derrick Gordon) //Fury (Nick Fury) //Iron Man (Tony Stark) //Captain America (Steve Roders) //Black Widow (Natasha Romanoff) //Captain Marvel (Carol Danvers) //Black Panther (T'Challa T'Chaka) //Thor (Thor Odinson) //Hulk (Bruce Banner) //Vision (Victor Shade) //Ant Man (Scott Lang) //Dr. Strange (Steven Strange) //Rocket (Rocket Raccoon) //Shuri (Shuri T'Chaka) //Hawkeye (Clint Barton) //Spider Man (Peter Parker) //Star Lord (Peter Quill) //Mantis (Mandy Celestine) //Scarlet Witch (Wanda Maximoff) //Winter Soldier (James Buchanan) //Pepper (Virginia Potts) //Falcon (Sam Wilson) #endregion //passwords #region Passwords from private.config var myPassword = WebConfigurationManager.AppSettings["myPassword"]; var demoPassword = WebConfigurationManager.AppSettings["demoPassword"]; var userPassword = WebConfigurationManager.AppSettings["seededPassword"]; #endregion //Add Avengers User Accounts #region Add Avengers as users. if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "master", UserName = "******", Email = "*****@*****.**", FirstName = "Derrick", LastName = "Gordon", Alias = "Derrick" }, myPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "nickfury", UserName = "******", Email = "*****@*****.**", FirstName = "Nick", LastName = "Fury", Alias = "Fury", AvatarPath = "/Avatars/AvengersAvatars/fury.jpeg" }, demoPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "ironman", UserName = "******", Email = "*****@*****.**", FirstName = "Tony", LastName = "Stark", Alias = "Iron Man", AvatarPath = "/Avatars/AvengersAvatars/ironman.jpg" }, demoPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "captamerica", UserName = "******", Email = "*****@*****.**", FirstName = "Steve", LastName = "Rogers", Alias = "Captain America", AvatarPath = "/Avatars/AvengersAvatars/cap.jpg" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "blackwidow", UserName = "******", Email = "*****@*****.**", FirstName = "Natasha", LastName = "Romanov", Alias = "Black Widow", AvatarPath = "/Avatars/AvengersAvatars/nat.jpg" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "captmarvel", UserName = "******", Email = "*****@*****.**", FirstName = "Carol", LastName = "Danvers", Alias = "Captain Marvel", AvatarPath = "/Avatars/AvengersAvatars/danvers.jpg" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "thorodinson", UserName = "******", Email = "*****@*****.**", FirstName = "Thor", LastName = "Odinson", Alias = "Thor", AvatarPath = "/Avatars/AvengersAvatars/thor.jpg" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "blackpanther", UserName = "******", Email = "*****@*****.**", FirstName = "T'Challa", LastName = "T'Chaka", Alias = "Black Panther", AvatarPath = "/Avatars/AvengersAvatars/tchalla.jpg" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "thehulk", UserName = "******", Email = "*****@*****.**", FirstName = "Bruce", LastName = "Banner", Alias = "Hulk", AvatarPath = "/Avatars/AvengersAvatars/hulk.jpg" }, demoPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "vision", UserName = "******", Email = "*****@*****.**", FirstName = "Victor", LastName = "Shade", Alias = "Vision", AvatarPath = "/Avatars/AvengersAvatars/vision.jpg" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "antman", UserName = "******", Email = "*****@*****.**", FirstName = "Scott", LastName = "Lang", Alias = "AntMan", AvatarPath = "/Avatars/AvengersAvatars/antman.jpg" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "drstrange", UserName = "******", Email = "*****@*****.**", FirstName = "Steven", LastName = "Strange", Alias = "Dr. Strange", AvatarPath = "/Avatars/AvengersAvatars/strange.jpg" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "rocket", UserName = "******", Email = "*****@*****.**", FirstName = "Rocket", LastName = "Raccoon", Alias = "Rocket", AvatarPath = "/Avatars/AvengersAvatars/rocket.jpg" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "shuri", UserName = "******", Email = "*****@*****.**", FirstName = "Shuri", LastName = "T'Chaka", Alias = "Shuri", AvatarPath = "/Avatars/AvengersAvatars/shuri.png" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "hawkeye", UserName = "******", Email = "*****@*****.**", FirstName = "Clint", LastName = "Barton", Alias = "Hawkeye", AvatarPath = "/Avatars/AvengersAvatars/hawkeye.jpg" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "spiderman", UserName = "******", Email = "*****@*****.**", FirstName = "Peter", LastName = "Parker", Alias = "Spider Man", AvatarPath = "/Avatars/AvengersAvatars/spiderman.png" }, demoPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "starlord", UserName = "******", Email = "*****@*****.**", FirstName = "Peter", LastName = "Quill", Alias = "Star Lord", AvatarPath = "/Avatars/AvengersAvatars/starlord.jpg" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "warmachine", UserName = "******", Email = "*****@*****.**", FirstName = "James", LastName = "Rhodes", Alias = "War Machine", AvatarPath = "/Avatars/AvengersAvatars/warmachine.jpg" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "mantis", UserName = "******", Email = "*****@*****.**", FirstName = "Mandy", LastName = "Celestine", Alias = "Mantis", AvatarPath = "/Avatars/AvengersAvatars/mantis.png" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "scarletwitch", UserName = "******", Email = "*****@*****.**", FirstName = "Wanda", LastName = "Maximoff", Alias = "Scarlet Witch", AvatarPath = "/Avatars/AvengersAvatars/scarletwitch.jpg" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "wintersoldier", UserName = "******", Email = "*****@*****.**", FirstName = "James", LastName = "Buchanan", Alias = "Winter Soldier", AvatarPath = "/Avatars/AvengersAvatars/wintersoldier.jpg" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "pepperpotts", UserName = "******", Email = "*****@*****.**", FirstName = "Virginia", LastName = "Potts", Alias = "Pepper", AvatarPath = "/Avatars/AvengersAvatars/pepperpotts.jpg" }, userPassword); } if (!context.Users.Any(u => u.Email == "*****@*****.**")) { userManager.Create(new ApplicationUser { Id = "falcon", UserName = "******", Email = "*****@*****.**", FirstName = "Sam", LastName = "Wilson", Alias = "Falcon", AvatarPath = "/Avatars/AvengersAvatars/falcon.jpg" }, userPassword); } context.SaveChanges(); #endregion //Avenger User Roles #region Role Assignment // //Admins: userManager.AddToRole("master", "Admin"); // //HeadOfHouse: userManager.AddToRole("nickfury", "HouseholdMember"); userManager.AddToRole("starlord", "HouseholdMember"); userManager.AddToRole("ironman", "HouseholdMember"); userManager.AddToRole("blackpanther", "HouseholdMember"); // //HouseholdMember: //nickfury //------------------------------------------- userManager.AddToRole("blackwidow", "HouseholdMember"); userManager.AddToRole("captmarvel", "HouseholdMember"); userManager.AddToRole("antman", "HouseholdMember"); userManager.AddToRole("hawkeye", "HouseholdMember"); //starlord //------------------------------------------ userManager.AddToRole("rocket", "HouseholdMember"); userManager.AddToRole("thorodinson", "HouseholdMember"); userManager.AddToRole("mantis", "HouseholdMember"); //ironman //------------------------------------------ userManager.AddToRole("vision", "HouseholdMember"); userManager.AddToRole("warmachine", "HouseholdMember"); userManager.AddToRole("pepperpotts", "HouseholdMember"); userManager.AddToRole("spiderman", "HouseholdMember"); //black panther //------------------------------------------ userManager.AddToRole("wintersoldier", "HouseholdMember"); userManager.AddToRole("falcon", "HouseholdMember"); userManager.AddToRole("captamerica", "HouseholdMember"); userManager.AddToRole("shuri", "HouseholdMember"); // //NoHousehold: userManager.AddToRole("thehulk", "NoHousehold"); userManager.AddToRole("drstrange", "NoHousehold"); userManager.AddToRole("scarletwitch", "NoHousehold"); context.SaveChanges(); #endregion //AccountTypes #region Account Types context.AccountTypes.AddOrUpdate( acct => acct.Name, new AccountType { Name = "Checking" }, new AccountType { Name = "Investment" }, new AccountType { Name = "Savings" }, new AccountType { Name = "Credit" }); context.SaveChanges(); #endregion //TransactionType #region Transaction Types context.TransactionTypes.AddOrUpdate( trans => trans.Name, new TransactionType { Name = "Deposit" }, new TransactionType { Name = "Payment" }); context.SaveChanges(); #endregion //SeededHouseholds #region Households context.Households.AddOrUpdate( hh => hh.Name, new Household { Name = "Shield", Created = DateTime.Now, Description = "The S.H.I.E.L.D. group.", HeadOfHouseId = "nickfury" }, new Household { Name = "Guardians", Created = DateTime.Now, Description = "The Guardians of the Galaxy (and friends).", HeadOfHouseId = "starlord" }, new Household { Name = "Stark Industries", Created = DateTime.Now, Description = "Tony Stark's warmongering business.", HeadOfHouseId = "ironman" }, new Household { Name = "Wakandians", Created = DateTime.Now, Description = "Members of the Wakanda royal family and their friends.", HeadOfHouseId = "blackpanther" }); context.SaveChanges(); #endregion //Add users to their households #region Seed UserHouseholds var shieldId = context.Households.FirstOrDefault(house => house.Name == "Shield").Id; var guardiansId = context.Households.FirstOrDefault(house => house.Name == "Guardians").Id; var starkId = context.Households.FirstOrDefault(house => house.Name == "Stark Industries").Id; var wakandaId = context.Households.FirstOrDefault(house => house.Name == "Wakandians").Id; //Shield houseHelper.AddUserToHousehold("nickfury", shieldId); houseHelper.AddUserToHousehold("blackwidow", shieldId); houseHelper.AddUserToHousehold("captmarvel", shieldId); houseHelper.AddUserToHousehold("hawkeye", shieldId); houseHelper.AddUserToHousehold("antman", shieldId); //Guardians houseHelper.AddUserToHousehold("starlord", guardiansId); houseHelper.AddUserToHousehold("rocket", guardiansId); houseHelper.AddUserToHousehold("thorodinson", guardiansId); houseHelper.AddUserToHousehold("mantis", guardiansId); //Stark houseHelper.AddUserToHousehold("ironman", starkId); houseHelper.AddUserToHousehold("pepperpots", starkId); houseHelper.AddUserToHousehold("warmachine", starkId); houseHelper.AddUserToHousehold("vision", starkId); houseHelper.AddUserToHousehold("spiderman", starkId); //Wakanda houseHelper.AddUserToHousehold("captamerica", wakandaId); houseHelper.AddUserToHousehold("shuri", wakandaId); houseHelper.AddUserToHousehold("blackpanther", wakandaId); houseHelper.AddUserToHousehold("wintersoldier", wakandaId); houseHelper.AddUserToHousehold("falcon", wakandaId); context.SaveChanges(); #endregion }