public async Task <int> InsertAsync(PostInsertDapper post)
        {
            string sqlInsert = @"INSERT INTO
                [ChalengeLike].[Post]
                (
                    Id,
                    ApplicationId,
                    UserId,
                    CreatedDate,
                    Title,
                    Liked
                )
                VALUES
                (
                    @Id,
                    @ApplicationId,
                    @UserId,
                    @CreatedDate,
                    @Title,
                    @Liked
                );";
            var    result    = await _dapperContext.DapperConnection.ExecuteAsync(sqlInsert, post);

            return(result);
        }
Beispiel #2
0
        public async Task <PostResponseViewModel> InsertAsync(PostRequestViewModel postViewModel)
        {
            var postRequestModel = _mapper.Map <PostRequestModel>(postViewModel);
            var applicationId    = _identityService.GetApplicationId();

            var postInsertDapper = new PostInsertDapper()
            {
                Id            = postRequestModel.Id,
                ApplicationId = applicationId,
                UserId        = postRequestModel.User.Id,
                CreatedDate   = DateTime.Now,
                Title         = postRequestModel.Title,
                Liked         = postRequestModel.Liked
            };

            Task.WaitAll(new Task[2] {
                _userRepository.InsertAsync(new UserInsertDapper()
                {
                    Id            = postRequestModel.User.Id,
                    ApplicationId = applicationId,
                    Name          = postRequestModel.User.Name
                }),
                _postRepository.InsertAsync(postInsertDapper)
            });

            return(new PostResponseViewModel()
            {
                Id = postInsertDapper.Id,
                CreatedDate = postInsertDapper.CreatedDate,
                Title = postInsertDapper.Title,
                Liked = postInsertDapper.Liked
            });
        }