コード例 #1
0
        public override PostRatingEntity Create(PostRatingEntity entity)
        {
            IRepository <PostEntity> repositoryOfPost = new RepositoryOfPost(context, serviceOfSearch);

            var Post = entity.Post;

            if (Post == null)
            {
                Post = repositoryOfPost.Read(a => a.Id == entity.PostId);
            }

            Post.SumOfScore += entity.Score;
            Post.CountOfScore++;
            repositoryOfPost.Update(Post);

            return(base.Create(entity));
        }
コード例 #2
0
        public override async Task Delete(PostRatingEntity entity)
        {
            IRepository <PostEntity> repositoryOfPost = new RepositoryOfPost(context, serviceOfSearch);

            var Post = entity.Post;

            if (Post == null)
            {
                Post = repositoryOfPost.Read(a => a.Id == entity.PostId);
            }

            Post.SumOfScore -= entity.Score;
            Post.CountOfScore--;
            repositoryOfPost.Update(Post);

            await base.Delete(entity);
        }
コード例 #3
0
        public override PostRatingEntity Update(PostRatingEntity entity, params Expression <Func <PostRatingEntity, object> >[] properties)
        {
            IRepository <PostEntity> repositoryOfPost = new RepositoryOfPost(context, serviceOfSearch);

            var lastPostRating = Read(a => a.Id == entity.Id);
            var Post           = entity.Post;

            if (Post == null)
            {
                Post = repositoryOfPost.Read(a => a.Id == entity.PostId);
            }

            Post.SumOfScore -= lastPostRating.Score;
            Post.SumOfScore += entity.Score;
            repositoryOfPost.Update(Post);

            entity = base.Update(entity, properties);
            return(entity);
        }
コード例 #4
0
        public override async Task Delete(UserProfileEntity entity)
        {
            IRepository <PostEntity> repositoryOfPost = new RepositoryOfPost(context, serviceOfSearch);
            var posts = entity.Posts;

            if (posts == null)
            {
                posts = repositoryOfPost.ReadMany(new System.Linq.Expressions.Expression <System.Func <PostEntity, bool> >[] { a => a.UserProfileId == entity.Id }, null);
            }
            posts = posts.ToList();
            if (posts != null)
            {
                foreach (var item in posts)
                {
                    repositoryOfPost.Delete(item);
                }
            }
            await base.Delete(entity);
        }