public async Task <IActionResult> DeleteEvent(int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var e = await _repo.GetEvent(id); var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); var user = await _repo.GetUser(e.EventOwnerId); if (user.Id != currentUserId) { return(Unauthorized()); } _repo.Delete(e); if (await _repo.SaveAll()) { return(StatusCode(200)); } throw new Exception("Failed on save."); }
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.SenderDeleted && messageFromRepo.RecipientDeleted) { _repo.Delete(messageFromRepo); } if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception("Error deleting the message"); }
public async Task <IActionResult> DeletePhoto(int userId, int id) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var photoFromRepo = await _repo.GetPhoto(id); if (photoFromRepo == null) { return(NotFound()); } var deleteParams = new DeletionParams(photoFromRepo.PublicId); var result = _cloudinary.Destroy(deleteParams); if (result.Result == "ok") { _repo.Delete(photoFromRepo); } if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest("Failed to delete the photo")); }
public async Task <ActionResultResponse> Delete(string socialnetworkId) { var socialnetworkinfo = await _socialnetworkRepository.GetInfo(socialnetworkId); if (socialnetworkinfo == null) { return(new ActionResultResponse(-1, _resourceService.GetString("SocialNetwork does not exists."))); } var result = await _socialnetworkRepository.Delete(socialnetworkId); return(new ActionResultResponse(result, result <= 0 ? _resourceService.GetString("Something went wrong. Please contact with administrator.") : _resourceService.GetString("Delete SocialNetwork successful."))); }