Ejemplo n.º 1
0
        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));
        }