Пример #1
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.SenderDelete = true;
            }

            if (messageFromRepo.RecipientId == userId)
            {
                messageFromRepo.RecipientDelete = true;
            }

            if (messageFromRepo.SenderDelete && messageFromRepo.RecipientDelete)
            {
                _repo.Delete(messageFromRepo);
            }

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

            throw new Exception("Error deleting the message");
        }
Пример #2
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var user = await _repo.GetUser(userId);

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

            var Photofromrepo = await _repo.GetPhoto(id);

            if (Photofromrepo.IsMain)
            {
                return(BadRequest("This is the main photo"));
            }

            if (Photofromrepo != null)
            {
                var Deleteparams = new DeletionParams(Photofromrepo.PublicId);
                var reults       = _cloudinary.Destroy(Deleteparams);

                if (reults.Result == "ok")
                {
                    _repo.Delete(Photofromrepo);
                }
            }
            else
            {
                _repo.Delete(Photofromrepo);
            }

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

            return(BadRequest("Fail To Delete"));
        }