public async Task <IActionResult> CreateMessge(int UserId, MessagesForDto msgfrdto) { var sender = await _repo.Getuser(UserId); if (sender.Id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } msgfrdto.SenderId = UserId; var recipient = await _repo.Getuser(msgfrdto.RecipaintId); if (recipient == null) { return(BadRequest("the user doesn't exsist")); } var msgfrommap = _mapper.Map <Messages>(msgfrdto); _repo.Add(msgfrommap); if (await _repo.SaveAll()) { var mesgtoreturn = _mapper.Map <MessageToReturnDto>(msgfrommap); return(CreatedAtRoute("GetMessage", new { id = msgfrommap.Id }, mesgtoreturn)); } throw new Exception("Creating the message failed on save"); }
public async Task <IActionResult> LikeUser(int id, int recipientId) { if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var like = await _context.GetLikes(id, recipientId); if (like != null) { return(BadRequest("you already liked the profile")); } if (await _context.Getuser(recipientId) == null) { return(NotFound()); } like = new Likes { LikerId = id, LikeeId = recipientId }; _context.Add <Likes>(like); if (await _context.SaveAll()) { return(Ok()); } return(BadRequest("Failed to like user")); }