Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }