Example #1
0
        public async Task <IActionResult> LikeUser(int id, int recipientId)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var Like = await _dating.GetLikes(id, recipientId);

            if (await _dating.GetUser(recipientId) == null)
            {
                return(NotFound());
            }

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

            var like = new Like {
                LikerId = id,
                LikeeId = recipientId
            };

            _dating.Add <Like>(like);
            if (await _dating.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("Failed to like User"));
        }