public IActionResult AddPostPart([FromBody] AddPostPartParameters model) { Claim idClaim = User.FindFirst("sub"); AddPostPartReturnModel ret = _postPartService.AddPostPart(model.PostId, model.Title, idClaim.Value); return(Ok(Json(ret))); }
public AddPostPartReturnModel AddPostPart(int postId, string title, string currUserId) { AddPostPartReturnModel ret = new AddPostPartReturnModel(); Post post = _postSet.Include(p => p.PostParts).FirstOrDefault(p => p.Id == postId); if (post == null) { ret.IsActionSucceed = false; return(ret); } if (string.IsNullOrEmpty(currUserId) || post.UserInfoId != currUserId) { ret.IsActionSucceed = false; return(ret); } if (post.PostParts == null) { post.PostParts = new List <PostPart>(); } if (post.PostParts.Count >= 4) { ret.IsActionSucceed = false; return(ret); } PostPart newPostPart = new PostPart() { Title = title, Post = post }; _postPartSet.Add(newPostPart); if (_entityContext.SaveChanges() != 0) { ret.IsActionSucceed = true; ret.PostPartId = newPostPart.Id; } ; return(ret); }