コード例 #1
0
        public ServiceResult <PostDTO[]> GetFeedPosts(HttpContext httpContext)
        {
            var userId = _claimsService.GetFromClaims <int?>(httpContext, ClaimTypes.Sid);

            if (userId == null)
            {
                return(new ServiceResult <PostDTO[]>("UserId not found in claims"));
            }
            var posts = _postRepository.GetAll(p => p.User, p => p.Group)
                        .Where(p => IsFriend((int)userId, p.UserId) || IsInUsersGroup((int)userId, p))
                        .OrderByDescending(p => p.Id);
            var mappedPosts = _mapper.Map <PostDTO[]>(posts);

            foreach (var post in mappedPosts)
            {
                post.FirstName = post.User.FirstName;
                post.LastName  = post.User.LastName;
                post.GroupName = post.Group.GroupName;
                if (post.User.ImageSmallPath != null)
                {
                    var authorImage = _imageService.GetImage(post.User.ImageSmallPath);
                    post.UserImage = authorImage.SuccessResult;
                }
            }

            return(new ServiceResult <PostDTO[]>(mappedPosts));
        }
コード例 #2
0
        public ServiceResult <PostDTO[]> AddPost(int groupId, string postContent, HttpContext httpContext)
        {
            if (String.IsNullOrWhiteSpace(postContent))
            {
                return(new ServiceResult <PostDTO[]>("Post content is empty"));
            }
            var dbGroup = _groupRepository.GetBy(g => g.Id == groupId);

            if (dbGroup == null)
            {
                return(new ServiceResult <PostDTO[]>("Group doesn't exist"));
            }
            var userId = _claimsService.GetFromClaims <int?>(httpContext, ClaimTypes.Sid);

            if (userId == null)
            {
                return(new ServiceResult <PostDTO[]>("UserId not found in claims"));
            }
            var newPost = new Post {
                GroupId = groupId, UserId = (int)userId, Content = postContent
            };

            _postRepository.Insert(newPost);
            return(GetGroupsPosts(groupId));            //zwraca wszystkie posty tej grupy
        }
コード例 #3
0
        public ServiceResult <EventDTO> GetDetails(int eventId, HttpContext httpContext)
        {
            var userId = _claimsService.GetFromClaims <int?>(httpContext, ClaimTypes.Sid);

            if (userId == null)
            {
                return(new ServiceResult <EventDTO>("UserId not found in claims"));
            }
            var dbEvent = _eventRepository.GetBy(e => e.Id == eventId, e => e.Group);

            if (dbEvent == null)
            {
                return(new ServiceResult <EventDTO>("Event doesn't exist"));
            }
            var mappedEvent     = _mapper.Map <EventDTO>(dbEvent);
            var userJoinedEvent = _eventUsersRepository.GetBy(e => e.EventId == eventId && e.UserId == userId);

            mappedEvent.Joined    = userJoinedEvent != null;
            mappedEvent.GroupName = dbEvent.Group.GroupName;
            return(new ServiceResult <EventDTO>(mappedEvent));
        }
コード例 #4
0
        public ServiceResult <UserDTO> SetUserInfo(UserDTO userInfo, HttpContext httpContext)
        {
            var userId = _claimsService.GetFromClaims <int?>(httpContext, ClaimTypes.Sid);

            if (userId == null)
            {
                return(new ServiceResult <UserDTO>("UserId not found in claims"));
            }
            var dbUser = _userRepository.GetBy(u => u.Id == userId);

            if (dbUser == null)
            {
                return(new ServiceResult <UserDTO>("User doesn't exist"));
            }
            _mapper.Map(userInfo, dbUser);
            _userRepository.Update(dbUser);
            return(new ServiceResult <UserDTO>(userInfo));
        }