public async Task <ActionResult <Post> > DeletePost(int id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var postModel = await _postServices.GetByIdAsync(id);

            if (postModel == null)
            {
                return(NotFound());
            }

            await _postServices.DeleteAsync(postModel);

            var posts = await _postServices.GetAllAsync();

            return(Ok(posts));
        }
Example #2
0
        public async Task <ActionResult> Delete(int id)
        {
            try
            {
                var userId = await GetUserIdentityAsync();

                var postModel = await _postServices.GetByIdAsync(id);

                if (userId == postModel.IdentityUser)
                {
                    await _postServices.DeleteAsync(id, null);
                }

                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Example #3
0
        public async Task <ActionResult <PostModel> > DeletePostModel(int id)
        {
            if (id <= 0)
            {
                return(NotFound());
            }

            var post = await _postServices.GetByIdAsync(id);

            if (post == null)
            {
                return(NotFound());
            }

            _unitOfWork.BeginTransaction();
            await _postServices.DeleteAsync(id, post.UriImage);

            await _unitOfWork.CommitAsync();

            return(post);
        }
Example #4
0
        public async Task DeleteAsync(string id)
        {
            var postagens = await _postServices.GetPostsByUserAsync(id);

            var comentarios = await _commentPostRepository.GetCommentByUserAsync(id);

            var likes = await _likePostRepository.GetLikeByUserAsync(id);

            var amigos = await _amigosRepository.GetAllByUserAsync(id);

            var user = await _usuarioRepository.GetByIdAsync(id);

            foreach (var post in postagens)
            {
                await _postServices.DeleteAsync(post.Id, post.UriImage);
            }

            foreach (var comentario in comentarios)
            {
                await _commentPostRepository.DeleteAsync(comentario.Id);
            }

            foreach (var like in likes)
            {
                await _likePostRepository.DeleteAsync(like.Id);
            }

            foreach (var amigo in amigos)
            {
                await _amigosRepository.DeleteAsync(amigo.Id);
            }

            await _blobServices.DeleteBlobAsync(user.FotoPerfil);

            await _usuarioRepository.DeleteAsync(id);
        }