コード例 #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));
        }
コード例 #2
0
        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));
        }