Ejemplo n.º 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 _repo.GetLike(id, recipientId);

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

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


            like = new 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> CreateMessage(int userId, UserForMessageDto userForMessageDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            userForMessageDto.SenderId = userId;

            var recipient = await _repository.GetUser(userForMessageDto.RecipientId);

            if (recipient == null)
            {
                BadRequest("Could not find user!!");
            }

            var message = _mapper.Map <Message>(userForMessageDto);

            _repository.Add(message);

            // var messageToReturn = _mapper.Map<messageforEndUser>(message);

            if (await _repository.SaveAll())
            {
                var messageforEndUser = _repository.GetMessage(message.Id);
                var messageToReturn   = _mapper.Map <UserForMessageDto>(messageforEndUser.Result);
                return(CreatedAtRoute("GetMessage", new { userId, id = message.Id }, messageToReturn));
            }


            throw new System.Exception("Creating the message failed on save!!");
        }