public async Task <IActionResult> DeleteAppointment(int id, int userId)
        {
            // if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            // {
            //     return Unauthorized();
            // }

            var appointmentFromRepo = await _repo.GetAppointment(id);

            if (!userId.Equals(appointmentFromRepo.PatientId) && !userId.Equals(appointmentFromRepo.DoctorId))
            {
                return(Unauthorized());
            }

            // if (messageFromRepo.SenderId == userId)
            //     messageFromRepo.SenderDeleted = true;

            // if (messageFromRepo.RecipientId == userId)
            //     messageFromRepo.RecipientDeleted = true;

            // Only actually delete message if both sides of the conversation delete it
            // if (messageFromRepo.SenderDeleted && messageFromRepo.RecipientDeleted)
            _repo.Delete(appointmentFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception("Error deleting the appointment");
        }
Exemple #2
0
        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;
            }

            // Only actually delete message if both sides of the conversation delete it
            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> DeleteDocument(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var user = await _repo.getUser(userId);

            if (!user.Documents.Any(p => p.id == id))
            {
                return(Unauthorized());
            }

            var docFromRepo = await _repo.GetDocument(id);

            if (docFromRepo.PublicId != null)
            {
                var deleteParams = new DeletionParams(docFromRepo.PublicId);

                // checks that response and result comes back ok
                var result = _cloudinary.Destroy(deleteParams);

                if (result.Result == "ok")
                {
                    _repo.Delete(docFromRepo);
                }
            }

            if (docFromRepo.PublicId == null)
            {
                _repo.Delete(docFromRepo);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo"));
        }