public async Task <IActionResult> CreateMessage(int userId, MessageForCreationDTo messageForCreationDTo) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var recipient = await _repo.GetUser(messageForCreationDTo.RecipientId); var sender = await _repo.GetUser(userId); messageForCreationDTo.UserId = userId; if (await _repo.GetUser(messageForCreationDTo.RecipientId) == null) { return(BadRequest("Couldn't Find User!")); } var message = _mapper.Map <Message>(messageForCreationDTo); _repo.Add <Message>(message); if (await _repo.SaveAll()) { var messageForReturn = _mapper.Map <MessageToReturnDto>(message); return(CreatedAtRoute("getMessage", new { userId, id = message.Id }, messageForReturn)); } return(BadRequest("Failure in message sending!")); }
public async Task <IActionResult> LikeUser(int userId, int recipientId) { var like = await _repo.GetLike(userId, recipientId); if (like != null) { return(BadRequest("This user is already liked!")); } if (await _repo.GetUser(recipientId) == null) { return(NotFound()); } like = new Like { LikeeId = recipientId, LikerId = userId }; _repo.Add <Like>(like); if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest("Error Happened During Liking The User!")); }