Пример #1
0
        public async Task <BlogComment> UpsertAsync(BlogCommentCreate blogCommentCreate, int applicationUserId)
        {
            var dataTable = new DataTable();

            dataTable.Columns.Add("BlogCommentId", typeof(int));
            dataTable.Columns.Add("ParentBlogCommentId", typeof(int));
            dataTable.Columns.Add("BlogId", typeof(int));
            dataTable.Columns.Add("Content", typeof(string));

            dataTable.Rows.Add(blogCommentCreate.BlogCommentId, blogCommentCreate.ParentBlogCommentId, blogCommentCreate.BlogId, blogCommentCreate.Content);

            int?newBlogCommentId;

            using (var connection = new SqlConnection(_config.GetConnectionString("DefaultConnection")))
            {
                await connection.OpenAsync();

                newBlogCommentId = await connection.ExecuteScalarAsync <int?>("BlogComment_Insert", new { BlogComment = dataTable.AsTableValuedParameter("dbo.BlogCommentType") },
                                                                              commandType : CommandType.StoredProcedure);
            }

            newBlogCommentId = newBlogCommentId ?? blogCommentCreate.BlogCommentId;
            BlogComment blogComment = await GetAsync(newBlogCommentId.Value);

            return(blogComment);
        }
Пример #2
0
        public async Task <ActionResult <BlogComment> > Create(BlogCommentCreate blogCommentCreate)
        {
            var userId = await _unitOfWork.UserRepository.GetUserByUsername(User.GetUsername());

            var createdBlogComment = await _unitOfWork.BlogCommentRepository.CreateAsync(blogCommentCreate);

            return(Ok(createdBlogComment));
        }
Пример #3
0
        public async Task <ActionResult <BlogComment> > Create(BlogCommentCreate blogCommentCreate)
        {
            int applicationUserId = int.Parse(User.Claims.First(i => i.Type == JwtRegisteredClaimNames.NameId).Value);

            var createdBlogComment = await _blogCommentRepository.UpsertAsync(blogCommentCreate, applicationUserId);

            return(Ok(createdBlogComment));
        }
        public async Task <bool> CreateAsync(BlogCommentCreate blogComment)
        {
            var blogCommentToReturn = new BlogComment
            {
                Id      = blogComment.BlogCommentId,
                BlogId  = blogComment.BlogId,
                Content = blogComment.Content
            };
            await _context.BlogComments.AddAsync(blogCommentToReturn);

            var created = await _context.SaveChangesAsync();

            return(created > 0);
        }
 public Task <BlogComment> UpdateAsync(BlogCommentCreate blogCommentCreate, int applicationUserId)
 {
     throw new System.NotImplementedException();
 }