Beispiel #1
0
        public ResultDto Put(int id, [FromBody] CreateUpdateBookDto updateBook)
        {
            Book book = _bookRepository.Select.Where(r => r.Id == id).ToOne();

            if (book == null)
            {
                throw new LinCmsException("没有找到相关书籍");
            }

            bool exist = _bookRepository.Select.Any(r => r.Title == updateBook.Title && r.Id != id);

            if (exist)
            {
                throw new LinCmsException("图书已存在");
            }

            //book.Image = updateBook.Image;
            //book.Title = updateBook.Title;
            //book.Author = updateBook.Author;
            //book.Summary = updateBook.Summary;
            //book.Summary = updateBook.Summary;

            //使用AutoMapper方法简化类与类之间的转换过程
            _mapper.Map(updateBook, book);

            _bookRepository.Update(book);

            return(ResultDto.Success("更新图书成功"));
        }
Beispiel #2
0
        private Task OpenCreateBookModalAsync()
        {
            NewDialogOpen = true;
            NewBookDto    = new CreateUpdateBookDto();

            return(Task.CompletedTask);
        }
        public async Task UpdateAsync(long id, CreateUpdateBookDto updateBook)
        {
            Book book = _bookRepository.Select.Where(r => r.Id == id).ToOne();

            if (book == null)
            {
                throw new LinCmsException("没有找到相关书籍");
            }

            bool exist = _bookRepository.Select.Any(r => r.Title == updateBook.Title && r.Id != id);

            if (exist)
            {
                throw new LinCmsException("图书已存在");
            }

            //book.Image = updateBook.Image;
            //book.Title = updateBook.Title;
            //book.Author = updateBook.Author;
            //book.Summary = updateBook.Summary;
            //book.Summary = updateBook.Summary;

            //使用AutoMapper方法简化类与类之间的转换过程
            _mapper.Map(updateBook, book);

            await _bookRepository.UpdateAsync(book);
        }
Beispiel #4
0
        public async Task UpdateAsync(Guid id, [FromBody] CreateUpdateBookDto input)
        {
            var book = await _bookRepository.GetAsync(id);

            book.Name        = input.Name;
            book.Price       = input.Price;
            book.IsAvailable = input.IsAvailable;
        }
Beispiel #5
0
        public async Task UpdateAsync(Guid id, [FromBody] CreateUpdateBookDto input)
        {
            var book = await _bookDbContext.Books.SingleAsync(b => b.Id == id);

            book.Name        = input.Name;
            book.Price       = input.Price;
            book.IsAvailable = input.IsAvailable;

            await _bookDbContext.SaveChangesAsync();
        }
        public async Task CreateAsync(CreateUpdateBookDto createBook)
        {
            bool exist = _bookRepository.Select.Any(r => r.Title == createBook.Title);

            if (exist)
            {
                throw new LinCmsException("图书已存在");
            }

            Book book = _mapper.Map <Book>(createBook);
            await _bookRepository.InsertAsync(book);
        }
Beispiel #7
0
        private Book GetBook()
        {
            CreateUpdateBookDto createBook = new CreateUpdateBookDto()
            {
                Title   = Guid.NewGuid().ToString(),
                Author  = Guid.NewGuid().ToString().Substring(0, 10),
                Image   = Guid.NewGuid().ToString(),
                Summary = Guid.NewGuid().ToString(),
            };
            Book book = Mapper.Map <Book>(createBook);

            return(book);
        }
Beispiel #8
0
        private Task OpenEditingBookModalAsync(BookDto book)
        {
            EditingDialogOpen = true;
            EditingBookId     = book.Id;
            EditingBookDto    = new CreateUpdateBookDto
            {
                Name        = book.Name,
                Price       = book.Price,
                PublishDate = book.PublishDate,
            };

            return(Task.CompletedTask);
        }
Beispiel #9
0
        public async Task <Guid> CreateAsync([FromBody] CreateUpdateBookDto input)
        {
            var book = new Book
            {
                Name        = input.Name,
                Price       = input.Price,
                IsAvailable = input.IsAvailable
            };

            await _bookRepository.InsertAsync(book);

            return(book.Id);
        }
Beispiel #10
0
        public ResultDto Post([FromBody] CreateUpdateBookDto createBook)
        {
            bool exist = _bookRepository.Select.Any(r => r.Title == createBook.Title);

            if (exist)
            {
                throw new LinCmsException("图书已存在");
            }

            Book book = _mapper.Map <Book>(createBook);

            _bookRepository.Insert(book);
            return(ResultDto.Success("新建图书成功"));
        }
Beispiel #11
0
        public async Task <Guid> CreateAsync([FromBody] CreateUpdateBookDto input)
        {
            var book = new Book
            {
                Name        = input.Name,
                Price       = input.Price,
                IsAvailable = input.IsAvailable
            };

            await _bookDbContext.Books.AddAsync(book);

            await _bookDbContext.SaveChangesAsync();

            return(book.Id);
        }
        public async Task PutAsync()
        {
            // Act
            CreateUpdateBookDto createUpdateBookDto = new CreateUpdateBookDto()
            {
                Author  = "luo",
                Summary = "lin-cms-dotnetcore从零到1是一本介绍一个SB开发的一个小系统",
                Title   = "lin-cms-dotnetcore从零到1"
            };

            HttpContent httpContent = new StringContent(JsonConvert.SerializeObject(createUpdateBookDto));

            var response = await Client.PostAsync($"/v1/book", httpContent);

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
Beispiel #13
0
        public IActionResult CreateModal()
        {
            var book = new CreateUpdateBookDto();

            return(View(book));
        }
Beispiel #14
0
        public async Task OnGetAsync()
        {
            var bookDto = await _bookAppService.GetAsync(Id);

            Book = ObjectMapper.Map <BookDto, CreateUpdateBookDto>(bookDto);
        }
        public async Task <UnifyResponseDto> PutAsync(int id, [FromBody] CreateUpdateBookDto updateBook)
        {
            await _bookService.UpdateAsync(id, updateBook);

            return(UnifyResponseDto.Success("更新图书成功"));
        }
        public async Task <UnifyResponseDto> CreateAsync([FromBody] CreateUpdateBookDto createBook)
        {
            await _bookService.CreateAsync(createBook);

            return(UnifyResponseDto.Success("新建图书成功"));
        }
Beispiel #17
0
 public virtual Task <BookDto> UpdateAsync(Guid id, CreateUpdateBookDto input)
 {
     return(_service.UpdateAsync(id, input));
 }
Beispiel #18
0
 public Books()
 {
     BookList       = new List <BookDto>();
     NewBookDto     = new CreateUpdateBookDto();
     EditingBookDto = new CreateUpdateBookDto();
 }
Beispiel #19
0
 public Task <BookDto> CreateAsync(CreateUpdateBookDto input)
 {
     return(_bookAppService.CreateAsync(input));
 }
Beispiel #20
0
 public Task <BookDto> UpdateAsync(Guid id, CreateUpdateBookDto input)
 {
     return(_bookAppService.UpdateAsync(id, input));
 }
Beispiel #21
0
 public void OnGet()
 {
     Book = new CreateUpdateBookDto();
 }
Beispiel #22
0
 public virtual Task <BookDto> CreateAsync(CreateUpdateBookDto input)
 {
     return(_service.CreateAsync(input));
 }