Пример #1
0
        public async Task <ActionResult <IEnumerable <PostModel> > > GetPostModel(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var posts = await _postServices.GetPostsByUserAsync(id);

            return(posts.ToList());
        }
Пример #2
0
        public async Task <List <PostViewModel> > GetPostsAsync(string userId)
        {
            var userLogado = await GetUserIdentityAsync();

            IEnumerable <PostModel> posts;

            var postLista = new List <PostViewModel>();

            if (userId == null)
            {
                posts = await _postServices.GetAllAsync();
            }
            else
            {
                posts = await _postServices.GetPostsByUserAsync(userId);
            }


            foreach (var post in posts)
            {
                var statusLikes = false;

                var usuario = await GetUsuarioModelAsync(post.IdentityUser);

                var likesList = await _likePostServices.GetPostByIdAsync(post.Id);

                var likePostModel = await _likePostServices.GetStatusAsync(userLogado, post.Id);

                if (likePostModel != null)
                {
                    statusLikes = true;
                }
                var listaComentarios = await GetListCommentByIdPost(post.Id);

                var(tempo, formatoDeTempo) = DefinirTempoPostagem(post.DataPostagem);

                var postViewModel = new PostViewModel(post, usuario, tempo, formatoDeTempo,
                                                      listaComentarios, likesList.Count(), statusLikes);

                postLista.Add(postViewModel);
            }

            return(postLista);
        }
Пример #3
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);
        }