public BusinessLayerResult <BlogUser> RemoveUserById(int id)
        {
            BusinessLayerResult <BlogUser> res = new BusinessLayerResult <BlogUser>();
            BlogUser       blogUser            = Find(x => x.Id == id);
            PostManager    postManager         = new PostManager();
            CommentManager commentManager      = new CommentManager();

            foreach (Post post in blogUser.Posts.ToList())
            {
                // Note ile ilişkili comment'lerin silinmesi
                foreach (Comment comment in post.Comments.ToList())
                {
                    commentManager.Delete(comment);
                }

                postManager.Delete(post);
            }
            foreach (Comment comment in blogUser.Comments.ToList())
            {
                commentManager.Delete(comment);
            }
            if (blogUser != null)
            {
                if (Delete(blogUser) == 0)
                {
                    res.AddError(ErrorMessageCode.UserCouldNotRemove, "Kullanıcı silinemedi.");
                    return(res);
                }
            }
            else
            {
                res.AddError(ErrorMessageCode.UserCouldNotFind, "Kullanıcı bulunamadı.");
            }

            return(res);
        }
Exemplo n.º 2
0
        public override int Delete(Category category)
        {
            PostManager    postManager    = new PostManager();
            CommentManager commentManager = new CommentManager();

            // Kategori ile ilişkili notların silinmesi gerekiyor.
            foreach (Post post in category.Posts.ToList())
            {
                // Note ile ilişkili comment'lerin silinmesi
                foreach (Comment comment in post.Comments.ToList())
                {
                    commentManager.Delete(comment);
                }

                postManager.Delete(post);
            }

            return(base.Delete(category));
        }