Exemplo n.º 1
0
        public async Task <IActionResult> CreateMessage(int userId, MessageForCreationDto messageForCreationDto)
        {
            var Sender = await _repo.GetUser(userId);

            if (Sender.Id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            messageForCreationDto.SenderId = userId;
            var Recipient = await _repo.GetUser(messageForCreationDto.RecipientId);

            if (Recipient == null)
            {
                return(BadRequest("Could not find the user"));
            }

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

            _repo.Add(message);
            if (await _repo.SaveAll())
            {
                var MessageToReturn = _mapper.Map <MessageToReturnDto>(message);
                return(CreatedAtRoute("GetMessage", new { userId, id = message.Id }, MessageToReturn));
            }
            throw new Exception("Creating the message failed");
        }
Exemplo n.º 2
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"));
        }