Exemple #1
0
        public int CreatePost(string body, int?groupId = null, string externalId = null)
        {
            var post = new Post {
                Created = DateTime.Now, Body = body
            };

            var user = _userContext.GetCurrentUser();

            int postId;

            using (var transaction = new TransactionScope())
            {
                postId = _postRepository.Create(post, user.Id);

                if (groupId.HasValue)
                {
                    _postRepository.AssociateWithGroup(postId, groupId.Value);
                }
                if (!string.IsNullOrWhiteSpace(externalId))
                {
                    _postRepository.AssociateWithExternalId(postId, externalId);
                }
                transaction.Complete();
            }
            return(postId);
        }