public HttpResponseMessage IsFollower(string handle)
        {
            try
            {
                IdentityUser user = _userService.GetCurrentUser();
                Account      acc  = _accountSrv.GetAccountByHandle(handle);
                if (acc != null)
                {
                    FollowerRequest  request = new FollowerRequest();
                    FollowNewsletter nwsInfo = new FollowNewsletter();
                    request.FollowerID = user.Id;
                    request.ProfileUID = acc.UserId;
                    nwsInfo.Email      = user.Email;
                    nwsInfo.Handle     = handle;

                    ItemResponse <FollowerCheck> response = new ItemResponse <FollowerCheck>();
                    response.Item = _followerSevice.IsFollower(request, nwsInfo);
                    return(Request.CreateResponse(HttpStatusCode.OK, response));
                }
                else
                {
                    throw new Exception("That Account does not exist");
                }
            }
            catch (Exception ex)
            {
                ErrorResponse response = new ErrorResponse(ex.Message);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, response));
            }
        }
Esempio n. 2
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));
        }