コード例 #1
0
        public async Task <ApiResponse> PhoneAvailabilityCheck(string id)
        {
            BoolDto available = new BoolDto()
            {
                Boolean = false
            };
            Task <int> t = _db.Users.CountAsync(us => us.PhoneNumber == id);
            await      t;
            int        count = t.Result;

            if (t.IsCompletedSuccessfully)
            {
                if (count == 0)
                {
                    available.Boolean = true;
                }
                return(new ApiResponse(200, "Retrieved Phone Availability", available));;
            }
            return(new ApiResponse(401, "Phone Availability Retrieved Error", available));;
        }
コード例 #2
0
        public async Task <PostDetailsDto> GetPostDetailsDto(int postId, int userId)
        {
            // bool userReaction;
            var photos = await _context.Photos.Where(x => x.PostId == postId).ToListAsync();

            List <PostPhotoDto> postPhotoDto = _mapper.Map <List <Photo>, List <PostPhotoDto> >(photos);

            var positiveReactions = await _context.Reactions.Where(x => x.PostId == postId && x.IsPositive == true).CountAsync();

            var negativeReactions = await _context.Reactions.Where(x => x.PostId == postId && x.IsPositive == false).CountAsync();

            PostReactionDto postReactionDto = new PostReactionDto
            {
                PositveReactions  = positiveReactions,
                NegativeReactions = negativeReactions
            };

            var comments = await _context.Comments.Where(x => x.PostId == postId).Include(x => x.User).Select(x => new PostCommentDto
            {
                CommentId = x.Id,
                UserId    = x.UserId,
                UserLogin = x.User.Login,
                Content   = x.Content,
                CreatedAt = x.CreatedAt
            }).ToListAsync();



            var reaction = await _context.Reactions.Where(x => x.PostId == postId && x.UserId == userId).FirstOrDefaultAsync();

            // var reaction =  await _context.Posts.Where(x => x.Id == postId && x.UserId == userId).FirstOrDefaultAsync();
            if (reaction != null)
            {
                bool    userReaction = reaction.IsPositive;
                BoolDto boolDto      = new BoolDto(userReaction);



                var postDetailsDto = await _context.Posts.Where(x => x.Id == postId).Select(x => new PostDetailsDto
                {
                    PostId       = postId,
                    UserId       = x.UserId,
                    AuthorLogin  = x.User.Login,
                    Description  = x.Description,
                    CreateAt     = x.CreateAt,
                    UserReaction = boolDto,
                    Photos       = postPhotoDto,
                    Reactions    = postReactionDto,
                    Comments     = comments
                }).FirstOrDefaultAsync();

                return(postDetailsDto);
            }
            else
            {
                var postDetailsDto = await _context.Posts.Where(x => x.Id == postId).Select(x => new PostDetailsDto
                {
                    PostId      = postId,
                    UserId      = x.UserId,
                    AuthorLogin = x.User.Login,
                    Description = x.Description,
                    CreateAt    = x.CreateAt,
                    Photos      = postPhotoDto,
                    Reactions   = postReactionDto,
                    Comments    = comments
                }).FirstOrDefaultAsync();

                return(postDetailsDto);
            }
        }