コード例 #1
0
        public async Task<Post> Add(Post post)
        {
            if (post == null) throw new ArgumentNullException(nameof(post));

            _dbContext.Posts.Add(post);
            await _dbContext.SaveChangesAsync();
            return post;
        }
コード例 #2
0
        public async Task <User> Add(User user)
        {
            if (user != null)
            {
                _dbContext.Users.Add(user);
                await _dbContext.SaveChangesAsync();

                return(user);
            }

            throw new ArgumentNullException(nameof(user));
        }
コード例 #3
0
        public async Task <Comment> Add(CommentOnType commentOn, Comment comment)
        {
            if (comment == null)
            {
                throw new ArgumentNullException(nameof(Comment));
            }

            if (!await IsCreatedByExistsByType(comment.CommentOnId, commentOn))
            {
                throw new NotSupportedException(
                          $"{commentOn.ToString()} does not exists in our system!!");
            }

            _dbContext.Comments.Add(comment);
            await _dbContext.SaveChangesAsync();

            return(comment);
        }