public IActionResult Relationship(string roommateId) { RoomieRepo roomieRepo = new RoomieRepo(_context); TransactionRepo transRepo = new TransactionRepo(_context); string userId = User.getUserId(); Roommate currentSignedInUser = roomieRepo.GetRoommate(userId); Roommate roommate = roomieRepo.GetRoommate(roommateId); List <RoommateTransaction> transactions = transRepo.GetAllRelationshipTransactions(userId, roommateId).ToList(); decimal relationshipBalance = transRepo.GetIndividualRelationshipBalance(userId, roommateId); RelationshipVM relVM = new RelationshipVM() { CurrentUser = currentSignedInUser, Roommate = roommate, OneRoommateTranstactions = transactions, RelationshipBalance = relationshipBalance }; return(View(relVM)); }
public IActionResult AddBill() { // For passing simple types. // return RedirectToAction("ManageBills", new { productID = 5, productName = "bob"}); string userId = User.getUserId(); RoomieRepo roomieRepo = new RoomieRepo(_context); Roommate currentSignedInUser = roomieRepo.GetRoommate(userId); IEnumerable <Roommate> roommates = roomieRepo.GetAllOtherRoommates(userId); AddTransactionVM addTransactionVM = new AddTransactionVM { currentUser = currentSignedInUser, otherRoommates = roommates }; return(View(addTransactionVM)); }
public IActionResult Profile() { //get current users total balance string userId = User.getUserId(); TransactionRepo TransRepo = new TransactionRepo(_context); decimal totalBalance = TransRepo.GetTotalBalance(userId); //get all other roommates RoomieRepo roomieRepo = new RoomieRepo(_context); IEnumerable <Roommate> roommates = roomieRepo .GetAllOtherRoommates(userId); //create and fill VMs //get current user name Roommate currentSignedInUser = roomieRepo.GetRoommate(userId); RoomieAndBalance currentUser = new RoomieAndBalance() { Balance = totalBalance, Roommate = currentSignedInUser }; ProfilePageVM ppvm = new ProfilePageVM() { CurrentUser = currentUser, RoomiesRelationships = new List <RoomieAndBalance>(), }; //get all other balances with roomies, put them into a VM, //which then goes into another bigger VM if (roommates != null) { foreach (var roomie in roommates) { decimal relationshipBalance = TransRepo.GetIndividualRelationshipBalance(userId, roomie.RoommateId); RoomieAndBalance roomieAndBalance = new RoomieAndBalance() { Roommate = roomie, Balance = relationshipBalance }; ppvm.RoomiesRelationships.Add(roomieAndBalance); } } return(View(ppvm)); }
public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true //2s delay System.Threading.Thread.Sleep(2000); // Require the user to have a confirmed email before they can log on. var user = await _userManager.FindByEmailAsync(model.Email); if (user != null) { if (!await _userManager.IsEmailConfirmedAsync(user)) { ModelState.AddModelError(string.Empty, "You must have a confirmed email to log in."); return(View(model)); } } var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : true); if (result.Succeeded) { _logger.LogInformation("User logged in."); //we need another condition here which checks if the user has a household or not UserRepo userRepo = new UserRepo(_context); var userId = userRepo.FindUserId(model.Email); RoomieRepo roomieRepo = new RoomieRepo(_context); var roommate = roomieRepo.GetRoommate(userId); if (roommate != null) { if (roommate.HomeId == null) { return(RedirectToAction("JoinCreateHousehold", "Household")); } else { return(RedirectToAction("Profile", "Home")); //return RedirectToLocal(returnUrl); } } } if (result.RequiresTwoFactor) { return(RedirectToAction(nameof(LoginWith2fa), new { returnUrl, model.RememberMe })); } if (result.IsLockedOut) { _logger.LogWarning("User account locked out."); return(RedirectToAction(nameof(Lockout))); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(View(model)); } } // If we got this far, something failed, redisplay form return(View()); }