public async Task <IActionResult> DeleteMessage(int id, int userId) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var messageFromRepo = await _repo.GetMessage(id); if (messageFromRepo.SenderId == userId) { messageFromRepo.SenderDeleted = true; } if (messageFromRepo.RecipientId == userId) { messageFromRepo.RecipientDeleted = true; } if (messageFromRepo.RecipientDeleted && messageFromRepo.SenderDeleted) { _repo.Delete(messageFromRepo); } if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception("Error Deleting Message"); }
public async Task <IActionResult> DeleteUser(int userId, int id) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var user = await _repo.GetUser(id); _repo.Delete(user); if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest("Failed To Delete User")); }