Ejemplo n.º 1
0
        public async Task <IActionResult> LikeUser(int id, int recipientId)
        {
            //Checking user is authorized or not
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var like = await _repo.GetLike(id, recipientId);

            if (like != null)
            {
                return(BadRequest("You already like this user"));
            }

            if (await _repo.GetUser(recipientId) == null)
            {
                return(NotFound());
            }
            like = new Models.Like
            {
                LikerId = id,
                LikeeId = recipientId
            };
            _repo.Add <Like>(like);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to like user."));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PostLike(int id, int recipientId)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var like = await _repo.GetLike(id, recipientId);

            if (like != null)
            {
                return(BadRequest("already liked the user"));
            }
            if (_repo.GetUser(recipientId) == null)
            {
                return(NotFound());
            }

            like = new Like()
            {
                LikeeId = recipientId,
                LikerId = id
            };
            _repo.Add <Like>(like);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("failed to like to user"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> LikeUser(int id, int recepientId)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var like = await _datingRepo.GetLike(id, recepientId);

            if (like != null)
            {
                return(BadRequest("You already liked this user."));
            }

            if (await _datingRepo.GetUser(recepientId) == null)
            {
                return(NotFound());
            }

            like = new Like {
                LikerId = id,
                LikeeId = recepientId
            };

            _datingRepo.Add <Like>(like); // this is not async as this is not adding to db at this point,.

            if (await _datingRepo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Unable to like user"));
        }