Ejemplo n.º 1
0
        public async Task <IActionResult> MessageDelete(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 messages");
        }
Ejemplo n.º 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 photfromrepo = await _repo.GetPhoto(id);

            if (photfromrepo.mainphoto)
            {
                return(BadRequest("You can not delete your main photo"));
            }

            if (photfromrepo.PublicId != null)
            {
                var deleteparamas = new DeletionParams(photfromrepo.PublicId);
                var result        = _cloudinary.Destroy(deleteparamas);
                if (result.Result == "ok")
                {
                    _repo.Delete(photfromrepo);
                }
            }
            if (photfromrepo.PublicId == null)
            {
                _repo.Delete(photfromrepo);
            }


            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("Failed to delete the photo"));
        }