Exemple #1
0
        public async Task CreateAsync(CreateAuthorInput input)
        {
            // 如果在这里直接用实体对象,但用automapper来
            // var author = new Author(GuidGenerator.Create(), input.Name, input.Description);

            // 使用automapper映射创建实体
            var author = ObjectMapper.Map <CreateAuthorInput, Author>(input);
            await _authorRepository.InsertAsync(author);
        }
        public async Task <ActionResult> Create(CreateAuthorInput input)
        {
            try
            {
                await _AuthorService.CreateAsync(input);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(NotFound(ex));
            }
        }
 public async Task Should_Create_A_Valid_Author()
 {
     await WithUnitOfWorkAsync(async() =>
     {
         await Should.NotThrowAsync(async() =>
         {
             var input = new CreateAuthorInput
             {
                 Name        = "张家老三",
                 Description = "中国内地不知名网络小说作家"
             };
             await _authorAppService.CreateAsync(input);
         });
     });
 }
 public async Task CreateAsync(CreateAuthorInput input)
 {
     try
     {
         var newPub = new Author
         {
             Name = input.Name
         };
         _context.Authors.Add(newPub);
         await _context.SaveChangesAsync();
     }
     catch (Exception err)
     {
         throw err;
     }
 }
        public async Task Should_Create_A_Valid_Author()
        {
            await WaitUnitOfWorkAsync(async() =>
            {
                // 没有返回值的,用是否抛出异常判定
                Should.NotThrow(async() =>
                {
                    var input = new CreateAuthorInput
                    {
                        Name        = "天下霸唱",
                        Description = "盗墓小说祖师"
                    };

                    await _authorAppService.CreateAsync(input);
                });
            });
        }
        public Author CreateAuthor(CreateAuthorInput inputAuthor)
        {
            _logger.LogInformation($"Creating author {inputAuthor.Name}");
            var work = _data.EfContext.Works.Find(inputAuthor.WorkId);

            var author = new MapperConfiguration(cfg =>
                                                 cfg.CreateMap <CreateAuthorInput, Author>()
                                                 .ForMember("Work", opt => opt.MapFrom(c => work)))
                         .CreateMapper()
                         .Map <Author>(inputAuthor);

            var createdAuthor = _data.EfContext.Authors.Add(author);

            _data.EfContext.SaveChanges();

            _logger.LogInformation($"Author {inputAuthor.Name} is created successfully (id = {createdAuthor.Entity.Id})");
            return(createdAuthor.Entity);
        }
Exemple #7
0
 public async Task Create(CreateAuthorInput input)
 {
     Author output = ObjectMapper.Map <Author>(input);
     await _authorManager.Create(output);
 }
 public async Task Create(CreateAuthorInput input)
 {
     var author = _objectMapper.Map <Author>(input);
     await _authorManager.Create(author);
 }
Exemple #9
0
 public async Task CreateAsync(CreateAuthorInput input)
 {
     var author = ObjectMapper.Map <CreateAuthorInput, Author>(input);
     await _authorRepository.InsertAsync(author);
 }