public override async Task Delete(PostEntity entity)
        {
            IRepository <SectionEntity>    repositoryOfSection    = new RepositoryOfSection(context);
            IRepository <CommentEntity>    repositoryOfComment    = new RepositoryOfComment(context, serviceOfSearch);
            IRepository <PostRatingEntity> repositoryOfPostRating = new RepositoryOfPostRating(context, serviceOfSearch);
            IRepository <PostTagEntity>    repositoryOfPostTag    = new RepositoryOfPostTag(context);
            var section = entity.Section;

            if (section == null)
            {
                section = repositoryOfSection.Read(a => a.Id == entity.SectionId);
            }
            if (section != null)
            {
                section.CountOfUsage--;
                repositoryOfSection.Update(section);
            }
            var comments = entity.Comments;

            if (comments == null)
            {
                comments = repositoryOfComment.ReadMany(new Expression <Func <CommentEntity, bool> >[] { a => a.PostId == entity.Id }, null);
            }
            comments = comments.ToList();
            foreach (var item in comments)
            {
                repositoryOfComment.Delete(item);
            }
            var postRatings = entity.PostRatings;

            if (postRatings == null)
            {
                postRatings = repositoryOfPostRating.ReadMany(new Expression <Func <PostRatingEntity, bool> >[] { a => a.PostId == entity.Id }, null);
            }
            postRatings = postRatings.ToList();
            foreach (var item in postRatings)
            {
                repositoryOfPostRating.Delete(item);
            }
            var postTags = entity.Tags;

            if (postTags == null)
            {
                postTags = repositoryOfPostTag.ReadMany(new Expression <Func <PostTagEntity, bool> >[] { a => a.PostId == entity.Id }, null);
            }
            postTags = postTags.ToList();
            foreach (var item in postTags)
            {
                repositoryOfPostTag.Delete(item);
            }
            serviceOfSearch.DeletePost(entity);
            await base.Delete(entity);
        }
Exemple #2
0
        public override async Task Delete(CommentLikeEntity entity)
        {
            IRepository <ApplicationUserEntity> repositoryOfApplicationUser = new RepositoryOfApplicationUser(context, serviceOfSearch);
            IRepository <CommentEntity>         repositoryOfComment         = new RepositoryOfComment(context, serviceOfSearch);
            var comment = entity.Comment;

            if (comment == null)
            {
                comment = repositoryOfComment.Read(a => a.Id == entity.CommentId);
            }
            comment.CountOfLikes--;
            repositoryOfComment.Update(comment);
            var ApplicationUserOfComment = repositoryOfApplicationUser.Read(a => a.UserProfileId == comment.UserProfileId);

            ApplicationUserOfComment.CountOfLikes--;
            repositoryOfApplicationUser.Update(ApplicationUserOfComment);
            await base.Delete(entity);
        }