コード例 #1
0
ファイル: PostService.cs プロジェクト: UgurMamak/Blog-Backend
        [TransactionScopeAspect]//+++
        public IDataResult <Post> Add(PostCreateDto postCreateDto, string imageName)
        {
            var post = new Post
            {
                Title     = postCreateDto.Title,
                Content   = postCreateDto.Content,
                ImageName = imageName,
                UserId    = postCreateDto.UserId,
                Created   = DateTime.Now
            };

            _postDal.Add(post);
            var postSave = new SuccessDataResult <Post>(post, Messages.UserRegistered);

            string[] category = postCreateDto.CategoryId.Split("*");
            foreach (var item in category)
            {
                if (item != "")
                {
                    var postCategory = new PostCategoryCreateDto {
                        PostId = postSave.Data.Id, CategoryId = item
                    };
                    _postCategoryService.Add(postCategory);
                }
            }
            return(new SuccessDataResult <Post>(post, Messages.PostAdded));
        }
コード例 #2
0
ファイル: PostService.cs プロジェクト: UgurMamak/Blog-Backend
        [TransactionScopeAspect]//+++
        public IResult Update(PostUpdateDto post)
        {
            /*
             * var post2 = new Post
             * {
             *  Content = post.Content,
             *  Title = post.Title,
             *  Updated = DateTime.Now,
             *  Id = post.Id,
             *  UserId = post.UserId
             * };*/

            _postDal.Update2(post);
            if (post.CategoryId != null)
            {
                string[] category = post.CategoryId.Split("*");
                foreach (var item in category)
                {
                    if (item != "")
                    {
                        var postCategory = new PostCategoryCreateDto {
                            PostId = post.Id, CategoryId = item
                        };
                        _postCategoryService.Add(postCategory);
                    }
                }
            }


            //var postCategory2 = new PostCategory {PostId=post.Id,CategoryId=post.CategoryId, Id=post.PostCategoryId };
            // _postCategoryService.Update(postCategory2);
            return(new SuccessResult(Messages.PostUpdated));
        }
コード例 #3
0
        [HttpPost("add")]//+++
        public IActionResult Add(PostCategoryCreateDto postCategoryCreateDto)
        {
            var result = _postCategoryService.Add(postCategoryCreateDto);

            if (result.Success)
            {
                return(Ok(result.Message));
            }
            return(BadRequest(result.Message));
        }
コード例 #4
0
        public void MultipleAdd(PostCategoryCreateDto postCategoryCreateDto)
        {
            using (var context = new BlogDbContext())
            {
                var sorgu = new PostCategory
                {
                    CategoryId = postCategoryCreateDto.CategoryId,
                    PostId     = postCategoryCreateDto.PostId
                };

                context.PostCategories.Add(sorgu);
                context.SaveChanges();
            }
        }
コード例 #5
0
        [TransactionScopeAspect]//+++++
        public IResult Add(PostCategoryCreateDto postCategoryCreateDto)
        {
            var postCategory = new PostCategory
            {
                CategoryId = postCategoryCreateDto.CategoryId,
                PostId     = postCategoryCreateDto.PostId
            };

            var exist = PostCategoryExists(postCategory);

            if (exist.Success)
            {
                _postCategoryDal.MultipleAdd(postCategoryCreateDto);
            }
            //_postCategoryDal.Add(postCategory);

            return(new SuccessResult(Messages.CategoryAdded));
        }
コード例 #6
0
 //  [Produces("application/json")]
 public async Task <IActionResult> Deneme(PostCategoryCreateDto postCategoryCreateDto)
 {
     return(Ok(postCategoryCreateDto));
 }