예제 #1
0
        public IHttpActionResult Follow(FollowingDto dto)
        {
            var userId = User.Identity.GetUserId();

            if (_context.Followings.Any(f => f.FolloweeId == userId && f.FolloweeId == dto.FolloweeId))
            {
                return(BadRequest("Following already exists."));
            }

            var following = new Following
            {
                FollowerId = userId,
                FolloweeId = dto.FolloweeId
            };

            _context.Followings.Add(following);
            _context.SaveChanges();

            return(Ok());
        }
        public IActionResult Follow([FromBody] FollowingDto dto)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            var exists = _context.Followings.Any(a => a.FollowerId == userId && a.FolloweeId == dto.FolloweeId);

            if (exists)
            {
                return(BadRequest("Following already exists."));
            }

            var following = new Following
            {
                FollowerId = userId,
                FolloweeId = dto.FolloweeId
            };

            _context.Followings.Add(following);
            _context.SaveChanges();

            return(Ok(JsonConvert.SerializeObject(dto)));
        }
예제 #3
0
        public IHttpActionResult Follow(FollowingDto followingDto)
        {
            var currentUserId = User.Identity.GetUserId();

            var exists = _context.Followings.Any(f => f.FollowerId == currentUserId && f.FolloweeId == followingDto.FolloweeId);

            if (exists)
            {
                return(BadRequest("Following already exists"));
            }

            var following = new Following
            {
                FollowerId = currentUserId,
                FolloweeId = followingDto.FolloweeId
            };

            _context.Followings.Add(following);
            _context.SaveChanges();

            return(Ok());
        }