Ejemplo n.º 1
0
        public ActionResult Main(int id = 0)
        {
            bool isMain     = false;
            bool isFollower = false;
            int  accountID  = (int)Session["userID"];
            List <DiaryForProfileDto> diariesForProfileDto;

            if (id == 0 || accountID == id)
            {
                isMain = true;
            }
            else
            {
                accountID  = id;
                isFollower = _followerService.IsFollower((int)Session["userID"], accountID);
            }

            if (isMain)
            {
                diariesForProfileDto = Mapper.Map <List <DiaryForProfileDto> >(_diaryService.GetDiariesForOwnAccount(accountID));
            }
            else if (isFollower)
            {
                diariesForProfileDto = Mapper.Map <List <DiaryForProfileDto> >(_diaryService.GetDiariesForFollower(accountID));
            }
            else
            {
                diariesForProfileDto = Mapper.Map <List <DiaryForProfileDto> >(_diaryService.GetDiariesForPublic(accountID));
            }

            AccountForProfileDto accountForProfileDto = Mapper.Map <AccountForProfileDto>(_accountService.GetAccount(accountID));
            int followerCount  = _followerService.GetFollowerCount(accountID);
            int followingCount = _followerService.GetFollowingCount(accountID);

            ProfileViewModel profileViewModel = new ProfileViewModel
            {
                AccountInfo    = accountForProfileDto,
                DiariesInfo    = diariesForProfileDto,
                IsOwnProfile   = isMain,
                IsFollower     = isFollower,
                FollowerCount  = followerCount,
                FollowingCount = followingCount
            };

            return(View(profileViewModel));
        }