コード例 #1
0
        public IHttpActionResult PostPost(PostModel post)
        {
            // Validate request
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Check that the corresponding blog exists
            if (!_blogRepository.Any(b => b.BlogID == post.BlogID))
            {
                throw new Exception("Unable to add the post to the database, as it does not correspond to a blog");
            }

            //Set up new Post object, populated from input post
            Post dbPost = new Post();

            dbPost.Update(post);

            // Add the new Post object to the DB
            _postRepository.Add(dbPost);

            // Save the changes in the database
            try
            {
                _unitOfWork.Commit();
            }
            catch (Exception e)
            {
                throw new Exception("Unable to add the post to the database", e);
            }

            // Set post ID in PostModel object with the ID
            //  that was set in the DB post after db.SaveChanges
            post.PostID = dbPost.PostID;
            return(CreatedAtRoute("DefaultApi", new { id = post.PostID }, post));
        }
コード例 #2
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create(PostViewModel postVM)
        {
            if (ModelState.IsValid)
            {
                var data = Mapper.Map <Post>(postVM);
                _postRepository.Add(data);
                _postRepository.SaveChanges();

                var post = _postRepository.Find(x => x.CreatedDate == data.CreatedDate &&
                                                x.Title == data.Title &&
                                                x.Url == data.Url &&
                                                x.CategoryId == data.CategoryId &&
                                                x.Status == data.Status).FirstOrDefault();
                //handle Tags
                var tags = postVM.Tag.Split(',');
                _tagRepository.AddTagToPost(post.Id, tags);

                return(RedirectToAction("Index"));
            }
            var category = _postCategoryRepository.GetAll().Where(x => x.Status == Status.IsAvtive);

            ViewBag.Category = category;
            return(View());
        }
コード例 #3
0
        /// <summary>
        /// Add Post record
        /// </summary>
        /// <param name="post">Post object</param>
        /// <returns>New Post record</returns>
        public Post Add(Post post)
        {
            if (post.Title == null)
            {
                post.Title = Guid.NewGuid().ToString();
                post.Url   = post.Title;
            }

            if (post.Keywords == null)
            {
                post.Keywords = string.Empty;
            }

            post.Category   = null;
            post.PostedOn   = DateTime.UtcNow;
            post.ModifiedOn = post.PostedOn;
            post.CreatedOn  = post.PostedOn;
            post.Published  = false;

            var response = _postRepository.Add(Mapper.Map <Post, PostEntity>(post));

            post.Id = response.Id;
            return(post);
        }
コード例 #4
0
 public void Post([FromBody] Post post)
 {
     postRepo.Add(post);
 }
コード例 #5
0
 public async Task <int> CreatePostAsync(Post post)
 {
     _postRepository.Add(post);
     return(await _postRepository.SaveAsync());
 }
コード例 #6
0
 public IActionResult Post(Post post)
 {
     _postRepository.Add(post);
     return(CreatedAtAction("Get", new { id = post.Id }, post));
 }
コード例 #7
0
 public Post Add(Post post)
 {
     return(postRepository.Add(post));
 }
コード例 #8
0
ファイル: PostsController.cs プロジェクト: hjsmwz/StackPosts_
        public Post AddPost([FromBody] Post post)
        {
            _repo.Add(post);

            return(post);
        }
コード例 #9
0
 public void AddPost(Post post)
 {
     postRepository.Add(post);
 }
コード例 #10
0
ファイル: PostService.cs プロジェクト: Wylliancp/Mini-Blog
 public async Task Add(Post obj)
 {
     await _repository.Add(obj);
 }
コード例 #11
0
 public void CreatePost(Post Post)
 {
     PostRepository.Add(Post);
 }
コード例 #12
0
 public Post Create(Post post)
 {
     return(_postRepository.Add(post));
 }
コード例 #13
0
        public async Task <IEnumerable <PostViewModel> > Handle(ForwardPostsCommand request, CancellationToken cancellationToken)
        {
            // 被转发的帖子对象list
            var toBeForwardedPosts = await _postRepository.GetPostsAsync(request.ForwardPostIds);

            // 被转发的帖子转发过的原始帖子对象list
            var originalPosts = await _postRepository.GetPostsAsync(toBeForwardedPosts.Where(p => p.ForwardedPostId != null).Select(p => p.ForwardedPostId.Value).ToList());

            var myId = Guid.Parse(_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var me   = await _userRepository.GetByIdAsync(myId);

            var posts = new List <Domain.AggregatesModel.PostAggregate.Post>();

            toBeForwardedPosts.ForEach(toBeForwardedPost =>
            {
                // 创建新帖子
                var score = (DateTime.Now - DateTime.UnixEpoch.AddSeconds(me.CreatedTime)).TotalHours <= _scoreRewardSettings.NewUserHour ? me.PostScore + _scoreRewardSettings.NewUserPost : me.PostScore;
                var post  = Domain.AggregatesModel.PostAggregate.Post.CreatePost(request.Text, request.Commentable, request.ForwardType, request.ShareType,
                                                                                 request.Visibility, request.ViewPassword, request.SystemTag, request.PublicTags, request.PrivateTag, null, request.Latitude, request.Longitude, request.LocationName,
                                                                                 request.Address, request.CityCode, request.FriendIds, null, score, myId, request.ShowOriginalText);

                post.SetForwardPostId(toBeForwardedPost);
                _postRepository.Add(post);
                posts.Add(post);

                // 增加被转发帖子的转发数和积分
                toBeForwardedPost.IncreaseForwardCount(_scoreRewardSettings.ForwardPost);

                // 被转发帖子是转发贴时,还要增加原始帖的转发数和积分
                if (toBeForwardedPost.ForwardedPostId != null)
                {
                    var originalPost = originalPosts.FirstOrDefault(p => p.Id == toBeForwardedPost.ForwardedPostId.Value);
                    originalPost.IncreaseForwardCount(_scoreRewardSettings.ForwardPost);
                }
            });

            if (await _postRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken))
            {
                var forwardInfos = new List <ForwardInfo>();

                foreach (var post in posts)
                {
                    var forwardedPost = toBeForwardedPosts.FirstOrDefault(p => p.Id == post.ForwardedPostId.Value);

                    if (forwardedPost == null)
                    {
                        forwardedPost = originalPosts.FirstOrDefault(p => p.Id == post.ForwardedPostId.Value);
                    }

                    // 如果帖子为审核通过,取得新帖和被转发帖中被@的用户id以便发送被@通知
                    IEnumerable <Guid> atUserIds = new List <Guid>();
                    if (post.PostAuthStatus == PostAuthStatus.Authenticated)
                    {
                        atUserIds = await _postQueries.GetAtUserIdsAsync(post);
                    }

                    forwardInfos.Add(new ForwardInfo
                    {
                        ForwardUserId      = myId,
                        OriginalPostUserId = forwardedPost.UserId,
                        OriginalPostId     = post.ForwardedPostId.Value,
                        NewPostId          = post.Id,
                        AtUserIds          = atUserIds
                    });
                }

                await SendPostForwardedEventAsync(forwardInfos);
            }

            return(await _postQueries.GetPostsAsync(posts.Select(p => p.Id).ToList()));
        }
コード例 #14
0
 public void UploadPhoto(Post post)
 {
     _postRepo.Add(post);
 }
コード例 #15
0
 public Post Add(Post entity)
 {
     return(repository.Add(entity));
 }
コード例 #16
0
 public Post Add(Post product)
 {
     return(_postRepository.Add(product));
 }
コード例 #17
0
ファイル: PostController.cs プロジェクト: mroyski/Minimize
 public void Post([FromBody] Post post)
 {
     post.PostTime = DateTime.Now;
     postRepo.Add(post);
 }
コード例 #18
0
        public void AddMappedPost(PostCreateVM vm, Guid[] categories)
        {
            Post post = _mapper.Map <Post>(vm);

            _postRepository.Add(post, categories);
        }
コード例 #19
0
 public Post PostPosts([FromBody] Post post)
 {
     post.Users_Id = _userManager.GetUserId(User);
     return(postRepository.Add(post));
 }
コード例 #20
0
 public void Add(PostViewModel obj)
 {
     _postRepository.Add(obj);
     _unitOfWork.Commit();
 }
コード例 #21
0
 public void AddPost(Post post)
 {
     _postRepository.Add(post);
     _unitOfWork.Complete();
 }
コード例 #22
0
 public void AddPost(Posts newPost)
 {
     _PostRepository.Add(newPost);
     _PostRepository.SaveChanges();
 }
コード例 #23
0
 public IActionResult Post(Post Post)
 {
     Post.DateCreated = DateTime.Now;
     _postRepository.Add(Post);
     return(CreatedAtAction("Get", new { id = Post.Id }, Post));
 }
コード例 #24
0
        public ViewModel.PostDTO IssuePost(int accountId, int sectionId, string title, string keyword, string content)
        {
            //account<=0 匿名用户
            if (accountId <= 0)
            {
                //poster = _accountRepository.GetFilter(it => it.Name.Equals(Constant.ACCOUNT_NAME_ANONYMOUS_EN)).FirstOrDefault();
                accountId = _accountRepository.GetFilter(it => it.Name.Equals(Constant.ACCOUNT_NAME_ANONYMOUS_EN)).First().Id;
            }

            Reply reply = new Reply()
            {
                Content   = content,
                Level     = 0,
                ReplyerId = accountId,
                ReplyTime = DateTime.Now
            };

            Post post = new Post()
            {
                Keyword    = keyword,
                PosterId   = accountId,
                PublicTime = DateTime.Now,
                Replies    = new List <Reply>()
                {
                    reply
                },
                ScanAccount = 0,
                SectionId   = sectionId,
                Title       = title
            };

            _postRepository.Add(post);
            _unitOfWork.Commit();

            PostDTO postDTO = _postRepository.Select(it => it.PosterId == accountId, it => new PostDTO()
            {
                Id          = it.Id,
                Keyword     = it.Keyword,
                PublicTime  = it.PublicTime,
                ScanAccount = it.ScanAccount,
                Title       = it.Title,
                Poster      = new AccountDTO()
                {
                    Id       = it.Poster.Id,
                    Age      = it.Poster.Age,
                    Email    = it.Poster.Email,
                    Name     = it.Poster.Name,
                    Password = it.Poster.Password,
                    Sex      = it.Poster.Sex,
                    Tel      = it.Poster.Tel,
                    RoleId   = it.Poster.Role.Id,//需要测试是否可用
                    RoleName = it.Poster.Role.Name
                },
                //不需要返回此属性的值
                //LastReply = it.Replies.OrderByDescending(e => e.Id).FirstOrDefault() == null ? null : new ReplyDTO()
                //{
                //    Id = it.Replies.OrderByDescending(e => e.Id).FirstOrDefault().Id,
                //    Content = it.Replies.OrderByDescending(e => e.Id).FirstOrDefault().Content,
                //    Level = it.Replies.OrderByDescending(e => e.Id).FirstOrDefault().Level,
                //    ReplyTime = it.Replies.OrderByDescending(e => e.Id).FirstOrDefault().ReplyTime
                //}
                ReplyAccount = it.Replies.Count
            },
                                                     it => it.RowVersion, false)
                              .FirstOrDefault();

            if (postDTO == null)
            {
                //throw new DomainException("未知错误");
                throw new DomainBusinessException("");
            }
            return(postDTO);
        }
コード例 #25
0
 public void CreatePost(Post post)
 {
     postRepository.Add(post);
 }
コード例 #26
0
 public Post Add(Post model)
 {
     return(_postRepository.Add(model));
 }
コード例 #27
0
ファイル: PostService.cs プロジェクト: kehao12/Learning
 public Post Add(Post Post)
 {
     return(_postRepository.Add(Post));
 }
コード例 #28
0
 private async Task AddPostDocumentToRepository(PostDocument postDocument)
 {
     await _postRepository.Add(postDocument);
 }
コード例 #29
0
ファイル: PostService.cs プロジェクト: xuanan0208/TeduShop
 public void Add(Post post)
 {
     _postRepository.Add(post);
 }
コード例 #30
0
ファイル: PostService.cs プロジェクト: barlasayaz/MVCForum
 /// <summary>
 /// Create a new post
 /// </summary>
 /// <param name="post"></param>
 /// <returns></returns>
 public Post Add(Post post)
 {
     post = SanitizePost(post);
     return(_postRepository.Add(post));
 }